GIT cheat sheet
by George Kosmidis / Published 4 years and 5 months ago, modified 4 years and 3 months ago
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
Command | Description |
---|---|
git init repo_name | Initializes a new repo locally |
git clone project_url | Clone a project locally |
git checkout branch_name | Checkout a branch |
git add . | Add all changes |
git push | Push all changes |
git pull | Pull all changes |
git commit -m "completed feature" | Commit all changes |
git checkout -b feature/branch | Create a new branch |
git rebase develop | Rebase |
git branch -D feature/branch | Delete a branch |
git reset --hard | Undo all changes |
git branch -m old_name new_name | Rename branch |
git merge feature | Merge 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!