Skip to content

Instantly share code, notes, and snippets.

@nikku
Last active October 30, 2016 13:46
Show Gist options
  • Save nikku/d9a5416ee4b7dd6a4b83 to your computer and use it in GitHub Desktop.
Save nikku/d9a5416ee4b7dd6a4b83 to your computer and use it in GitHub Desktop.
Git swizz army knife

git

reverting changes (if things go awry)

Find a well known {commit} via:

git reflog

Revert {branch} to well-known state ({commit}):

git checkout {branch}
git reset --hard {commit}

Checkout detached commit for inspection / experients

git checkout {commit}

Apply some commit (without history (!!)) on current branch:

git cherry-pick {commit-range}

branching + merging work folow

Create a new branch from something experimental:

git checkout -b {new-branch-name}
git push origin {new-branch-name} --set-upstream

stashing

Quickly switch context

git stash
git stash pop

git stash list

conflict handling

git rebase master
... cannot be applied ...

Fix and resolve conflicts in local working copy and continue:

git add {conflicting file(s)}
git rebase --continue

misc

Clean up uncommited changes

git clean -xdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment