Skip to content

Useful Git commands

Ralf Becker edited this page Oct 21, 2016 · 6 revisions

Branches

  • list all branches (incl. remotes)

git branch -a

  • master

    remotes/origin/14.2

  • switch to a branch you never checked out before, eg. above 14.2, and set up tracking

git branch --track <branch> origin/<branch>

  • switch to branch existing on your local repo

git checkout <branch>

  • merge a commit from a different branch (after pulling/fetching!)

git cherry-pick <sha1>

  • merge a not pushed commit from a different local repository

git --git-dir=../<some_other_repo>/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k

  • remove empty commits after import of partial repo via Github importer (has to be done with every branch and everyone has to clone the repo again!)

git filter-branch -f --commit-filter 'git_commit_non_empty_tree "$@"' HEAD; git push -f

Clone this wiki locally