Skip to content

Instantly share code, notes, and snippets.

@miekg
Created February 21, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miekg/b8fbbdf58403688bf149 to your computer and use it in GitHub Desktop.
Save miekg/b8fbbdf58403688bf149 to your computer and use it in GitHub Desktop.
# GIT HOWTO
## Partially Apply Pull Request
#. git checkout -b other-repo-master master
#. git pull https://github.com/other-repo/my-repo-name.git master
#. git checkout master
#. git cherry-pick COMMIT_HASH
## Fetch pull request
#. git fetch https://github.com/other-repo/my-repo-name.git remote-branch:local-branch
## Pulling remote branch
#. git pull
3. git co -b local-branch origin/remote-branch
## Cherry-pick with no commit
#. git cherry-pick -n COMMIT_HASH
## Merging
#. Keeping ours: `git checkout --ours FILE`
#. Keeping theirs: `git checkout --theirs FILE`
#. Stopping a botched merge: `git reset --merge` or `git merge --abort`
## Merging with vim
#. Start `git mergetool` and do your thing.
#. Choose the following (diff get)
* diffg RE (REmote)
* diffg BA (BAse)
* diffg LO (LOcal)
# Keep track of forked repository
#. git clone git@github.com:miekg/REPO.git
#. git remote add upstream git@github.com:USER/REPO.git
And then:
#. git fetch upstream
#. git rebase upstream/master
# Rebasing a branch (with possible outstanding pull request)
The same process basically.
# Find deleted filed
#. `git rev-list -n 1 HEAD -- <file_path>`.
#. Then checkout the version at the commit before. `git checkout <deleting_commit>^ -- <file_path>`. Or in one command, if $file is the file in question.
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
# Amend commit
#. git commit --amend -m "New commit message"
# Branch from commit
#. git checkout -b BRANCH COMMIT_HASH
# Delete remote branches
git push origin --delete BRANCH
# Checkout pull request
This is for <http://github.com> specifically. Add this to the section
`[remote "origin"]`:
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Then you can checkout specific pull requests like:
#. `git fetch origin`
#. `git checkout pr/999`
# Remove nothave
git clean [-fr] .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment