Title Text

my time machine works !!!

it's 2003 all over again

g±t

local

git staging

git add .  (current dir)

git add --all (entire repo -A)

git unstaging

git reset HEAD <file/folder>

staging tricks

git add -p (interactive staging y/n)

 

git diff --cached (diff staged files)

 

git diff HEAD (diff dirty files)

 

git checkout <file/folder> (discard dirty changes)

git commit

git commit -m <message>

 

git commit -am <message>

git uncommit

git reset --soft HEAD^

 

commit tricks

git reset --hard HEAD^ (undo last commit)

 

git revert <sha1> (create contrary changes)

 

git commit --amend (update last commit message)

 

wtf 

why?

​git stash
git pull
git commit -am "Fix crap"

fix!

​git add --all 
git commit -m "Fix crap"
git pull


remote explained

git fetch (update local repo)

 

git pull (fetch + merge)

 

git push (push modification to remote)

 

remote tricks

git fetch -p (remove local branches)

 

git push --all (push all branches)

 

git push --force (overwrite remote)

 

git push --tags (push tags to remote)

 

git push origin :<tag/branch> (remove from remote)

 

git  merging

git  merging

git  stash

git stash ("clean" working directory)

 

git stash save <name> (save named stash)

 

git stash list (list stashed items)

 

git stash pop (apply latest stash)

 

git stash apply <stash> (apply stash item)

 

git stash drop <stash> (remove stash item)

 

git  misc

 

git cherry-pick <sha1> (move one commit)

 

git whatchanged <file> (see history for file)

 

git diff <branch> (diff between branches)

 

git config --global alias.unstage 'reset HEAD' 

 

git  hooks

hook to git events like pre-push, post-push...

 

 

Examples

  • Remove unneeded code before commit (console.log)
  • Run tests before push
  • Run linting and other validations before push
  • Notify people on merges...

use SourceTree

Git @ OPSWAT

By Andrei Demian

Git @ OPSWAT

  • 1,064