Commit / Uncommit / Uncommit (message)
$ git commit -m "<message>"----$ git reset --hard <commit hash>Revert last ongoing commit$ git reset --soft HEAD~1 Revert last ongoing commit + discard changes. Git points to the first parent commit of the HEAD$ git reset --hard HEAD~1----Redoing the commit, new hash; not recommended if commit already pushed$ git commit --amend -m "<commit message>" Staging/Unstage
$ git add .$ git add <file name 1> <file name 2> ...----$ git reset HEAD <file name>$ git rm --cached (--cached will preserve the file in folder) Stashing/ Delete stash
Push new stash onto stash stack$ git stashList stored stashes$ git stash listApply stash to branch (files not staged)$ git stash apply (stash@{0..}Apply stash to branch + previously staged files$ git stash apply --indexRemove/Drop a stash from stack$ git stash drop stash@{0}Apply stash and immediately drop/remove it from stack$ git stash popDiscard all changes
$ git reset --hard $ git reset --hard HEAD$ git reset --hard <commit>$ git checkout HEAD <file>Local Changes/Commit History
Changed files in your working directory$ git statusChanges to tracked files$ git diff (<source branch>..<target branch>)Show all commits (newest first)$ git log (<source branch>..<target branch>)$ git shortlog (<source branch>..<target branch>)Who changed what and when in <file> / Trace changes line by line$ git blame <file>Initialization
Clone an existing repository$ git clone ssh://user@domain.com/repo.gitCreate a new local repository$ git initUpdate & Publsih
List all currently configured remotes$ git remote -v //--verboseShow origin remote$ git remote show originDownload changes from origin/master, dont integrate into HEAD$ git fetch <remote>Download changes from origin/master, integrate into HEAD$ git pull <remote> <branch> // origin masterPublish local changes on a remote$ git push <remote> <branch> // origin masterBranch (Creation) / (Pushing) / (Deletion) / (Merging)
$ git branch <name>$ git checkout <branch_name>Combined: create + switch head branch$ git checkout -d <branch_name>----$ git push -u origin <branch_name>$ git branch -a----$ git branch --merged$ git branch -d <branch_name>$ git branch -a$ git push origin --delete <branch_name>----$ git checkout master$ git pull origin master$ git branch --merged$ git merge <branch_name>$ git push origin masterOTHER
Git aliases (<level> : --global, --system, <none>/--local = repo)
Set$ git config <level> alias.<alias name> '<git command>'$ git config --global alias.cm "commit -m"$ git config --global alias.cm '!git add -A && git commit -m'Unset$ git config --global --unset alias.cmList$ git config --get-regexp ^alias\.$ git config -e (VIM mode. type :q to exit) Pretty log output from the console.
$ git log --graph --decorate --pretty=oneline --abbrev-commitMiscellaneous
Move to previous branch without typing its name$ git checkout -Cherry picking (select specific commits)
$ git checkout <branch name with commit that contains the fix>$ git cherry-pick <commit hash>$ git cherry-pick <starting-commit>..<ending-commit> (feat1~2..feat1~0)Archiving
$ git archive master --format=zip --output=../repbck.zipBundling
$ git bundle create ../repo.bundle master$ cd /Other/Computer/Folder$ git clone repo.bundle repo -b master" Implement the password retrieval mechanism - Add the "Lost password?" link into the login page - Send an email to the user with a link to renew the password"Fast-forward
Fast-forward feature (enabled by default) permits merge commits from different branches, as they were done subsequently in the same branch, obtaining a less-pronged repository.