Skip to content

Cheat Sheet

waja edited this page Dec 5, 2016 · 28 revisions
  • Create branch
 git branch <name>  
 git checkout <name>  
  • Edit your stuff
  • Commit your changes
 git commit <files>  
  • Push changes and delete local branch
 git checkout master  
 git push <origin> <branch>  
 git branch -D <branch>  
  • Add remote tracking branch
 git checkout -t <origin>/<remote branch>  
  • Delete your remote tracking branch
 git branch -d -r <origin>/<remote branch>  
  • Get rid of remote merged branches
 git branch --merged | awk '{print $1}' | xargs git branch -d
  • Purge non existing upstream branches
 git fetch -p <origin>
  • Fetch changes from upstream and push to private repository
 git pull --ff-only upstream master  
 git push <origin>  
  • Reset working copy to remote branch (here origin/master)
 git reset --hard origin/master  
  • Search for earliest tag containing a commit
 git describe --contains <blob>  
  • Search for strings
 git log -S<string> <files>  
  • Cloning specific branch into dir
 git clone user@git-server:project_name.git -b branch_name /some/folder
git merge --no-ff pr/1234
vi foo.bar
git commit --amend -a -v
  • Handling patches / merge from other remote (git-apply function)
 git cherry-pick -x <blob>
 git format-patch -o /tmp/ -1
 cat foo.patch | git am

Git cherry-pick from another repository
Patch-Workflows: git format-patch, git apply-patch, git am

  • Reword/edit commits
git rebase -i ${commit}~1
Clone this wiki locally