Zum Inhalt

git cheatsheet

Create a git repository

git init

git config

Configure git globally

git config --global set user.name "First Last"
git config --global set user.email foo@bar.com


Clone a repo using ssh (recommended for private repos)

git clone git@gitlab.com:user/repo.git

Clone using https:

git clone https://gitlab.com/user/repo.git


Fetch a remote branch

git fetch origin branchname

Push branch to the remote and create it's origin

git push -u origin feature

Then, check out this branch

git checkout branchname

Rename a branch that is currently checkout out

git branch -m new_name


On a feature branch feature originating from main branch, you can rebase like

git checkout feature
git rebase main


Reset the last 2 commits

git reset HEAD~2

Then, when you want to also revert changes of these commits (if the file existed, else it is unstaged):

# for all files    
git checkout .

# for a specific file
git checkout path/to/file


Tags are handy to mark releases of your software.

Push tags to remote

git push --tags

Delete a remote tag:

git push --delete origin tagname

Delete a tag locally:

git tag -d tagname

Make a tag

git tag tagname

remote urls

See current remote urls

git remote -v

Set a new remote url

git remote set-url origin https://gitlab.com/user/repo.git

Letztes Update: August 7, 2022
Erstellt: August 7, 2022