Show Menu
Cheatography

Git Cheat Sheet (DRAFT) by

Git Cheat sheet for #90DaysofDevops

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Setup

git config --global user.name "­nam­e"
Setting username
git config --global user.email "­nam­e@m­ail.co­m"
Setting the email

Start a project

git init dir
Create a local repo and initialise dir
git clone <ur­l>
Download remote repo

Make changes

git add file
Add file to staging
git add .
Stage all files
git commit -m "­mes­sag­e"
Commit all staged files to git
git commit --amend
Change the last (unpub­lished) commit

Review Repository

git status
List new/mo­dified files that are yet to be committed
git log --oneline
List commit history with commit-id
git diff commit-id1 commit-id2
Changes between two commits
git log
List all commits (from newest)
 

Branches

git branch
List all local branches
git branch new_branch
Create new branch
git checkout branch
Switch to branch and update the working directory
git checkout -b branch
Create new branch and switch to it
git branch -d branch
Delete a local branch
git branch -D branch
Delete a branch (merge­d/not)
git tag <ta­g>
Mark current commit with a tag

Revert and Reset

git revert <co­mmi­t-i­d>
Create new commit, reverting commits from the specified <co­mmi­t-i­d>
git reset <co­mmi­t-i­d>
Go back to previous commit, deleting all the commits ahead of it
git rm file
Removing a file from working directory and staging area, stage the removal
git checkout <co­mmi­t-i­d>
View a previous commit
 

Merge and Rebase

git merge branch
Merge branch to current HEAD
git rebase branch
Rebase current HEAD onto branch
git rebase --abort
Abort a rebase
git rebase --continue
Continue a rebase after resolving conflicts
git mergetool
Mergetool to resolve conflicts

Stashing

git stash
Store modified and staged changes
git stash -p
Partial stash
git stash list
List all stash
git stash apply
Re-apply all stash, not deleting from list
git stash pop
Re-apply latest stash and delete from list
git stash drop
Delete stash
git stash clear
Delete all stashes

Remote­,Pull and Push

git remote add <al­ias> <ur­l>
Add remote repo
git remote
View all remote connec­tions
git remote rename <al­ias>
Rename a remote connection
git remote remove <al­ias>
Remove a remote connection
git fetch <al­ias> <br­anc­h>
Fetch a specific branch(not merging with local repo)
git pull
Fetch remote repo copy and merge to local repo
git push <al­ias>
Update remote repo with the local repo content
git push <al­ias> <br­anc­h>
Upload to a specific branch