Show Menu
Cheatography

Git for DevOps Cheat Sheet (DRAFT) by

Git cheat sheet for DevOps

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

Setup

git config --global user.name “firstname lastname”
set a name that is identi­fiable for credit when review version history
git config --global user.email “[vali­d-e­mai­l]"
set an email address that will be associated with each history marker
git init
initialize an existing directory as a Git repository
git clone url
retrieve remote repository from url

Stage and Snapshot

git add file1.js
Stages file1.js
git add .
Stages the current directory and all its content
git reset file1.txt
unstage the file and keep the changes of file1.txt in working directory
git commit -m message
commit the staged changes with approp­riate message

Branch and Merge

git branch
show the list of branches
git branch b1
create new branch b1
git branch -d b1
delete branch b1
git checkout b1
switch to b1 branch
git merge b1
megre branch b1 to the current branch
 

Share and Update

git remote
show remote branches
git remote add repo url
add a new remote repo at url
git fetch
fetch all branches from origin
git pull
fetch and merge changes from remote repo to local repo
git push
push local changes to remote repository

Rewrite History

git reset HEAD~2
removes and unstage last two commits of current branch
git reset --soft HEAD~1
removes and stage last commit of current branch
git reset --hard HEAD~3
discards last three commits of current branch
git revert commitID
revert the given commitID
git rebase b1
merge changes of branch b1 to top of the current branch
git cherry­-pick commitID
merge the change of commitID to the current branch