Git Cheatsheet
A Distributed Version Control System.
Create a Repository Edit Repository Inspect Repository
Create new local repository Add file contents to the index Show the working tree status
$ git init $ git add {filename} $ git status
Create new local repository with name Add all files (new, modified, deleted) to staging View changes: Working Dir & Index
$ git init {repo name} $ git add -A $ git diff
Download remote repository Record changes to the repository with message View changes: Index & Local Repo
$ git clone {repo url} $ git commit -m "{Message}" $ git diff --cached
Resets the index and working directory from HEAD. View changes: Working Dir & Local Repo (HEAD)
Managing Branches $ git reset --hard HEAD $ git diff HEAD
List the branches, current one highlighted Resets file in index, keep working tree View changes in Local Repo between HEAD & HEAD-1
$ git branch $ git reset {file} $ git diff HEAD HEAD^
Create a new branch with name Resets the file in index and working tree View changes between Index & Local Repo (HEAD)
$ git branch {branch_name} $ git reset --hard {file} $ git diff --cached HEAD
Delete the branch Remove file from the working tree and index. View changes in Local Repo between id1 & id2
$ git branch -d {branch_name} $ git rm {file} $ git diff {commit1} {commit2}
Switch to specified branch and update working Remove file from the index and not index. View changes in Local Repo between tag1 & tag2
directory $ git rm --cached {file} $ git diff {tag1} {tag2}
$ git checkout {branch_name}
Move or rename a file, directory or symlink Show the commit history
Join changes from branch into current branch $ git mv {old} {new} $ git log
$ git merge {branch_name}
Show commit history
$ git log --oneline --graph --decorate –all
Working Dir Staging / Index Local Repo Remote Repo
Show log message and textual diff for the commit
add $ git show {commit}
commit
reset push Show what was changed in file by whom
checkout <branch>
checkout fetch $ git blame {filename}
pull / rebase
Version 0.3 https://www.code2bits.com
Git Cheatsheet
A Distributed Version Control System.
Git Configuration Sync Remote Repository Save / Stash Code Fragments
Set user name property in global config Shows a list of existing remote repositories Record the current state of working directory
$ git config --global user.name “{name}” $ git remote $ git stash
Set user email property in global config Add a remote name for repository at url Record the current state of working directory
$ git config --global user.email “{email}” $ git remote add {name} {repo_url} (Include untracked)
$ git stash -u
Display user name property value Shows list of existing remote repositories with urls
$ git config user.name $ git remote -v List the stash entries with its name.
$ git stash list
Display user name property value Download objects and refs from another
$ git config user.email repository Remove stash state and apply to working tree
$ git fetch $ git stash apply
Display all property values in global config
$ git config --global --list Fetch from and integrate with another repository Remove a single stash entry from the list of stash
or a local branch entries
Open default editor to modify local config file.
$ git pull {alias} {branch_name} $ git stash drop
$ git config -e --local
Same as git stash apply + git stash drop
Open default editor to modify global config file. Push branch to upstream remote repository
$ git stash pop
$ git config -e --global $ git push {alias} {branch_name}
Remove all the stash entries.
Open default editor to modify system config file.
Manage Tags $ git stash clear
$ git config -e --system
Create a tag reference Git Help
$ git tag {tag name}
Provide help on the different git commands
Create an “annotated” tag reference
$ git help
$ git tag -a {tag name}
Provide help on the specific git command
List all the tags
$ git help {command}
$ git tag --list
Provide help on the specific git command
Delete specific tag
$ git {command} --help
$ git tag --delete {tag name}
Version 0.3 https://www.code2bits.com