File ~/.gitconfig
[color]
diff = auto
status = auto
branch = auto
[core]
editor = vim
pager = less -r
[credential]
helper = cache --timeout=3600
git clone <url>
git checkout master
git pull
git checkout -b <branch>
git checkout master
git pull
git checkout <branch>
git checkout master
git pull
git checkout -b <branch> <existing-branch>
git checkout master
git pull
git checkout <branch>
git rebase master
git status
vim <conflict_file>
git add <conflict_file>
git rebase --continue
git push -f origin <branch>
If error fatal: 'upstream' does not appear to be a git repository
git remote -v
git remote add upstream <upstream-url>
git checkout master
git merge <branch>
git push origin master
git branch -d <branch>
git push origin :<branch>
git checkout <existing-branch>
git merge --no-ff <branch>
git push origin <existing-branch>
git branch -d <branch>
git push origin :<branch>
git checkout master
git merge <branch>
git push upstream master
git branch -d <branch>
git push origin :<branch>
git push origin master
git checkout master
git branch -m <old-name> <new-name>
git remote add <username> https://github.com/<username>/<repository>
git fetch <username>
git checkout -b <username>/<branch> <username>/<branch>
git reset --hard
git reset HEAD^
git commit --amend -m '<new-message>'
git log
# Search commit and copy its hash
git reset --hard <hash>
git log
# Search commit and copy its hash
git revert --no-edit <hash>
git checkout master
git fetch upstream
git merge upstream/master
git push origin master
If error fatal: 'upstream' does not appear to be a git repository
git remote -v
git remote add upstream <upstream-url>
git submodule sync
git submodule update --init
git submodule foreach git submodule sync
git submodule foreach git submodule update --init
Rebase
git log
git rebase -i HEAD~<n>
With <n>
last commits
Commands
p, pick = use commit
r, reword = use commit, but edit the commit message
f, fixup = use commit, but meld into previous commit and discard this commit's log message
Push rebase
git push -f origin <branch>
git rebase -i <hash>^
Modify pick
to edit
Make changes
git commit --all --amend --no-edit
git rebase --continue
git push -f origin <branch>
git fetch upstream
git rebase -i upstream/<other-branch>
Remove all pick
expect the ones to commit
git push -f origin <branch>
git cherry-pick <SHA>
git stash
git stash branch <branch> stash@{0}
git commit -am '<message>'
git push -u origin <branch>
git stash
git stash list
git stash pop stash@{<stash-index>}
git grep -n '<value>'
git ls-files | grep <filename>
git tag -l
git checkout tags/<tag>
git remote -v
git remote set-url origin https://<domain>/<org>/<repo>.git
git remote -v
git remote update