First Steps with Git and GitLab
Purpose
This guide is for new team members of NFDI4Immuno who are completely new to GitLab and Git. It focuses on the GitLab web interface and basic local Git setup on Windows, including how to create an SSH key, connect it to GitLab, set up Git locally, and work with a repository.
The NFDI4Immuno projects are hosted at https://codebase.helmholtz.cloud/nfdi4immuno. The metadata-schema project is used as an example throughout this guide - the steps are the same for any other NFDI4Immuno project, just replace the project name and URLs with those of the project you work on.
Once you are comfortable with the basics, continue with the GitLab Workflow Developer Role, which describes the full workflow used in the NFDI4Immuno projects.
Quick Reference Workflow
- Set up Git and SSH access on your Windows computer
- Clone the repository locally
- Create an Issue (to describe your task or bug)
- Create a Merge Request (MR) from that issue (this creates a branch and a draft MR)
- Make local changes (edit, commit, push)
- Make the MR ready to submit your work for review
Full Workflow
Steps 1 to 5 set up your computer and are only needed once. Steps 6 to 9 are repeated for every task you work on.
Step 1: Install Git on Windows
What: Install Git and the Git Bash terminal on your computer.
How:
- Download Git for Windows: https://git-scm.com/downloads
- Run the installer and follow the default options (you can leave most settings unchanged)
- After installation, open Git Bash (installed automatically with Git)
- Check that Git is installed correctly:
git --version
If it prints something like git version 2.x.x, you're good to go.
Step 2: Create an SSH Key
What: Generate a pair of SSH keys on your Windows computer.
Why: SSH keys allow you to connect securely to GitLab without typing your password each time.
How:
- Open Git Bash
- Run the following command (replace with your own email):
ssh-keygen -t ed25519 -C "your.email@institution.org"
- When asked for a file location, press Enter to accept the default (
/c/Users/<your name>/.ssh/id_ed25519) - When asked for a passphrase, you can either set one or leave it empty
You should now have two files in C:\Users\<your name>\.ssh:
id_ed25519: your private keyid_ed25519.pub: your public key
Avoid:
- Sharing your private key - keep this secret!
Step 3: Add the SSH Key to GitLab
What: Register your public key with your GitLab account.
How:
- Open a project page in GitLab, e.g. metadata-schema
- In the top-right corner, click your profile picture > Preferences
- In the left menu, select SSH Keys
- Open the public key file (
id_ed25519.pub) using Notepad:
notepad ~/.ssh/id_ed25519.pub
- Copy the entire contents of the file
- In GitLab, click Add new key to open the form. If the Key field is already shown, skip this step
- Paste the copied contents into the Key field
- Add a short Title (e.g., "My Windows laptop")
- Click Add key
Your computer is now authorized to connect to GitLab via SSH.
Step 4: Configure Git
What: Tell Git your name and email address. You only need to do this once on your machine.
How:
- Set your name and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@institution.org"
- Verify your settings:
git config --list
Step 5: Clone the Repository
What: Download the code to your local machine.
How:
- Go to the project page, e.g. https://codebase.helmholtz.cloud/nfdi4immuno/portal-infra/metadata-schema
- Click the blue Code button (top-right corner)
- Select the SSH option and copy the URL. For
metadata-schemait looks like:
git@codebase.helmholtz.cloud:nfdi4immuno/portal-infra/metadata-schema.git
- In Git Bash, navigate to a folder where you want to keep your projects, e.g.:
cd ~/Documents
- Clone the repository using the URL you copied, e.g.:
git clone git@codebase.helmholtz.cloud:nfdi4immuno/portal-infra/metadata-schema.git
You now have the project locally on your computer, in this example in the folder metadata-schema.
Step 6: Create an Issue
What: An issue describes what needs to be done.
How:
- Go to Issues in the project, e.g. metadata-schema Issues
- Click New issue
- Fill in:
- Title: Short and clear (e.g.,
Add new metadata field for antibodies) - Description: Briefly describe the goal
- Labels: Select relevant ones if available
- Assignee: Leave empty or assign to yourself (only one assignee per issue in free tier GitLab)
- Click Create issue
You've now created a task to work on.
Step 7: Create a Merge Request from the Issue
What: Create a branch and a draft merge request directly from the issue. Each issue should have its own branch. The name of the branch must start with the issue number, followed by a dash.
Why: Creating the merge request from the issue links your work to the issue and gives the branch the correct name automatically. The 'Draft' status signals that the work is still in progress.
How:
- Open the issue you just created
- Click the Create merge request button near the top right
- This automatically creates:
- A new branch named
{issue-number}-{issue-title}(e.g.,42-add-new-metadata-field-for-antibodies) - A draft merge request linked to the issue
- In the merge request creation page, verify:
- Target branch is set to
development(NOTmain) - this is also the branch your new branch is created from - The merge request is marked as Draft
- Click Create merge request at the bottom
A new branch and a draft merge request are now available for you.
Tips:
- See Introduction to Branch and Merge for an explanation of branches and of the
developmentbranch - The issue label is also updated at this point, see Step 4 of the GitLab Workflow Developer Role
Step 8: Make Local Changes
What: Get your branch, make changes, commit them, and push them to GitLab.
How:
- In Git Bash, move into your project folder, e.g.:
cd metadata-schema
- Check out your new branch:
git fetch origin
git checkout <your-branch-name>
- Make your code or document changes (e.g., update files)
- Stage and commit your changes:
git add .
git commit -m "feat: add new metadata field for antibodies"
- Push your work to GitLab:
git push
Your changes are now uploaded to GitLab and visible in the merge request.
Tips:
- See Git Commit Messages for how to write commit messages
Step 9: Make the Merge Request Ready for Review
What: Describe your changes and submit the merge request for review.
Why: The draft merge request was created before any work was done. A clear description and removing the 'Draft' status tell the reviewer what changed and that your work is ready to be looked at.
How:
- Go to Merge requests and open the merge request you created in Step 7
- Click Edit and check the form:
- Title: GitLab usually fills this automatically
-
Description: Describe what you did, and reference the issue (GitLab adds the
Closesline automatically when the merge request is created from the issue):Added a new metadata field for antibody type. Closes #123 -
Target branch: Usually
development - Reviewer: Assign your mentor or reviewer
- Click Save changes
- At the top of the merge request, click Mark as ready - the "Draft:" prefix is removed from the title
Your code is now ready for review.
Tips:
- Steps 8 to 11 of the GitLab Workflow Developer Role describe this in more detail, including checking the CI pipeline and updating the issue label
What Happens Next
- Your reviewer will check your MR and leave feedback
-
If you need to make fixes:
- Edit locally
-
Stage, commit, and push:
git add . git commit -m "fix: address review comments" git push -
The MR updates automatically
- Once approved, a maintainer will merge it
Additional Resources
- GitLab Documentation: https://docs.gitlab.com
- Git Basics: https://git-scm.com/book/en/v2/Getting-Started-What-is-Git