George Kosmidis

Microsoft MVP | Cloud Solutions Architect | .NET Software Engineer | Organizer of Munich .NET Meetup | Speaker

GIT cheat sheet

by George Kosmidis / Published 2 years ago
GIT cheat sheet

I know there are many cheat sheets around (here is one I like from GitHub) but I couldn’t find many that contain sequence of commands, from clone to merge and push. This is my version of a cheatsheet which I hope you will find useful.

Basic commands

git init repo_nameInitializes a new repo locally
git clone project_urlClone a project locally
git checkout branch_nameCheckout a branch
git add .Add all changes
git pushPush all changes
git pullPull all changes
git commit -m "completed feature"Commit all changes
git checkout -b feature/branchCreate a new branch
git rebase developRebase
git branch -D feature/branchDelete a branch
git reset --hardUndo all changes
git branch -m old_name new_nameRename branch
git merge featureMerge changes

Common operations

Clone a project locally:

cd path/for/project/without/project_name
git clone project_url

Create a new branch:

git checkout -b feature/branch
git push --set-upstream origin feature/branch

Rebase of a feature branch based on the develop branch:

git checkout develop:
git pull
git checkout feature/branch
git rebase develop
git rebase --continue

Merge feature branch into develop:

git checkout feature/branch
git pull
git status                       # should be clean
git checkout develop
git pull 
git status                       # should be clean
git merge feature/branch --no-ff
git push
git branch -D feature/branch     # deletes the branch!!!

Publish develop to master:

git checkout develop
git pull
git status                       # should be clean
git checkout master
git pull 
git status                       # should be clean
git merge develop
git push

Rename branch:

git checkout old_name
git pull
git branch -m old_name new_name
git push --set-upstream origin new_name

Sync changes with remote:

git add .
git commit -m "some changes"
git pull                     # always pull and merge locally
git push

Undo all changes on branch X:

git checkout X
git reset --hard

Do you commonly use any other sequence of git commands? Send it and I will include it!

This page is open source. Noticed a typo? Or something unclear?
Edit Page Create Issue Discuss
Microsoft MVP - George Kosmidis

My next events!

Nürnberg Convention Center NCC Ost
Bernhard-Nocht-Straße 97, D-20359, Hamburg