Git Commands

This is an overview of some useful Git commands.
Set up Git
Username
git config --global user.name usernamegit config --global user.email emailVim Editor
git config --global core.editor vimNotepad Editor
git config --global core.editor notepadAtom Editor
git config --global core.editor "atom --wait"Activate rename detection
git config diff.renames trueRepository
Create a repository
git initWrite data into a Object Database
git hash-object -w hello.txtGet content of object
git cat-file -p 56d90gfdzGet moved files
git log --summary -M90% | grep -e "^ rename"Get copied files
git log --summary -C90% | grep -e "^ copy"Get history of code lines
git blame -M -C -C -C foo.txtCommit
Choose specific files to commit
git add foo.txt bar.txtChoose a directory and everything under it to commit
git add directory/Choose the current directory and everything under it to commit
git add .Commit
git commit --message "Commit Message"Commit all changed files
git commit --allStatus
git statusDiff
Workspace vs. Stage
git diffDiff for file
git diff foo.txtStage vs. Repository
git diff --stagedDifference between two files
git diff 1c96fgt mainChange to the predecessor
git diff p03sr4f^!Count of changes
git diff --stat 1c96fgt 72ser18dContinuous text
--word-diffReset
Reset everything
git reset HEAD .Reset specific files/directories
git reset HEAD foo.txt src/test/Stashing
Stash changed files
git stash --include-untrackedRetrieve last saved changes
git stash popGet older stashed changes
git stash pop stash@{1}Stash list
git stash listInvestigate Commits
Show overview
git show 32rftsgzShow file content
git show 32rftsgz:src/main.ktShow root directory
git show 32rftsgz:Show directory “src”
git show 32rftsgz:srcShow directory “src” with subdirectories
git ls-tree -r 32rftsgz -- srcHistory
Log output
git logLast 3 commits
git log -n 3One line per commit
git log --onelineStatistics
git log --statShort statistic
git log --shortstat --onelineGraph
git log --graph --onelineBranches
List of branches
git branchCreate branch from current commit
git branch new-branchCreate branch from any commit
git branch new-branch 672dgzujCreate branch from existing branch
git branch new-branch existing-branchSwitch to a branch
git checkout mainCreate and switch branch
git checkout -b new-branchReset to older commit
git reset --hard rs29bnz1Delete not active branch
git branch -d branch-to-deleteRestore branch when commit hash is known
git branch deleted-branch ek183lp8 Get commit hashes
git reflogMerge
Merge feature branch into current branch
git merge featureStart mergetool
git mergetoolAbort merge
git merge --abortWorking With Repositories
List of remote tracking branches
git branch --list --remote --verboseFetch: Get branches from other repository
git fetch origin alpha masterCheck integrity of repositories
git fsck