Skip to content

How To Use Git

Madita Antonia Plogsties edited this page Apr 1, 2025 · 2 revisions

title: How to Use Git

There are plenty tutorials on this topic online. For a short overview of its functionalities I can recommend this short tutorial: https://www.youtube.com/watch?v=hwP7WQkmECE

Please watch out for the "scary" commands git reset (might delete your local changes), and git rebase (potentially deletes the entire project). Rebasing can sometimes still be a helpful tool, if you forgot to commit something in your local branch. If you're ever unsure about any of these "scary" commands, feel free to ask!

Anyway, here are some of the most frequent things to do with git:

Before you start working

Whenever you start working you should make sure that your branch is on the latest version. In order to avoid merge conflicts, download the latest version using:

git fetch origin
git pull

Uploading your work

# add all changes to your "staged changes"
git add .

# apply your changes locally (summarized your changes in the commit message)
git commit -m "<commit message>"

# check that you commited exactly the things you wanted to commit!
git show

# upload your local changes
git push

Checking out another branch

git checkout <branch-name>

Creating a new branch & merge requests

In most cases you'll want to create it using GitLab's UI.

Merging branches

In order to merge a branch into another one, first check out the target branch (the branch you want to update), then merge the source branch into it (the branch with the changes you want to apply):

# find any newly created branches
git fetch origin

# go to your target branch
git checkout <traget-branch>

# make sure you're on the latest version
git pull

# apply changes from the source branch to yours
git merge <source-branch>

Please note that in order to merge your changes into the main branch you should instead open a "merge request" via GitLab and wait for approval, to avoid breaking things.

Resolve a merge conflict

Merge conflicts occur, when two developers have edited the same file in parallel. To resolve them, manual work is needed. VSCode has some nice features that will assist you with resolving the merge conflict. The resolver will need to look at all places where changes differ, then decide which change to keep or how to combine both changes.

Please take extra care when merging branches, if this is done hastily, it can make the git history quite messy. It is always good to check using git log if the history you are about to push looks clean and how one would expect it.

Clone this wiki locally