Show Menu
Cheatography

Git Cheat sheet from GitHub

Setup

Set a user name
git config --global user.name "­[fi­rstname last name]"
Set an email
git config --global user.email "­[valid email]­"
Set automatic command line coloring
git config --global color.ui auto

Setup and INIT

Initialize a directory
git init
Clone an entire repository via URL
git clone [url]

Inspect and compare

Show the commits in B but no in A
git log branch­B..b­ranchA
Show the commits that changed file
git log --foll­ow[­file]
Show the diff of in A but no in B
git diff branch­B...br­anchA
Show any object in git
git show [SHA]

Tracking Path changes

Delete the path from project and stage the removal for commit
git rm [file]
Change an existing file path and stage the move
git mv [exist­ing­-path] [new-path]
Show all commits logs with movements in path
git log --stat -M

Ignoring patterns

Save a file with desired patterns as .gitignore
*.notes/
Configure the file
git config --global core.e­xcl­ude­sfile [file]
 

Stage and Snapshot

Show modified files in working directory
git status
Add a file to stage
git add [file]
Unstage a file
git reset [file]
Diff of what is changed but not staged
git diff
Diff of what is staged but not committed
git diff --staged
Commit your staged content
git commit -m "­[de­scr­iptive messag­e]"

Branch and Merge

List your branches
git branch
Create a new branch
git branch [branc­h-name]
Switch to another branch
git checkout
Merge the branch into the current
git merge [branch]
Show all the commits
git log

Share and Update

Add a git URL as an alias
git remote add [alias] [url]
Fetch down all the branches from git remote
git fetch [alias]
Merge remote branch into your current branch
git merge [alias­]/[­branch]
Transmit local branch commits to remote
git push [alias­][b­ranch]
Fetch and merge all commits
git pull

Rewrite History

Apply any commits of current branch ahead of specified one
git rebase [branch]
Clear staging area and rewrite working tree fro specified commit
git reset --hard [commit]

Temporary commits

Save modified and staged changes
git stash
List stack-­order of stashed file changes
git stash list
Write working from top of stash stack
git stash pop
Discard the changes from top of the stack
git stash drop
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Git Cheat Sheet
          Bash Dev Cheat Sheet

          More Cheat Sheets by Monz gomz

          Power Apps Cheat Sheet
          Movimiento curvilineo Cheat Sheet