Git Cheatsheet

Make a repository

git init
git init <folder>
git clone <url>
git clone <url> <folder>

Stage

git add <file>
git add --all

Commit

git commit -m ""
git commit -a -m ""
git commit --amend

Redo

git reset HEAD <file>
git checkout -- <file>
git reset --soft HEAD^
git reset --hard HEAD^
git reset --hard <commit>
git revert <commit>

Inspect

git status
git status -s
git diff
git diff --staged
git diff --cached
git diff <branch1> <branch2>
git difftool
git log
git log --oneline --decorate --graph --all

Remove

git rm <file>
git rm --cached <file>
git mv <oldname> <newname>

Branch

git branch
git branch -v
git branch --merged
git branch --no-merged
git branch <branch>
git branch -d <branch>
git checkout <branch>
git checkout -b <branch>
git merge <branch>
git mergetool
git rebase <ontobranch>

Tag

git tag
git tag <tag>
git tag -a <tag> -m ""
git tag <tag> <commit>
git tag -d <tag>
git show <tag>
git push <remote> <tag>
git push <remote> --tags
git checkout -b <branch> <tag>

Remote

git remote -v
git remote add <remote> <url>
git remote show <remote>
git remote rename <oldname> <newname>
git remote rm <remote>
git branch -u <remotebranch>
git branch -vv
git branch -a
git fetch <remote>
git fetch --all
git pull
git push <remote> <branch>
git push <remotebranch> --delete <branch>

Useful

git checkout master git remote add upstream git fetch upstream git rebase upstream/master git push -f origin master