Force push SHA

git reset --hard SHA
git push --force -n



git add
git commit --amend
git push --force -n



git stash
git stash pop


Revert all changes

git clean -df
git checkout -- .


PR check list
1. Review your PR first in GHE before sharing with anyone else.
2. Remove all white space.
3. Review in AppCode.
4. PR should include good description, reviews, and link to story.


How to checkout someone elses remote branch

git remote add joe
git fetch joe player_state_notifications
git checkout player_state_notifications

Note: A pull request is just a branch so to see a PR, just checkout the branch.


How to resolve merge conflict

#Checkout from master
git checkout master
git pull upstream master

#Merge master to your branch
git checkout um683
git merge master

# Re-push branch
git push origin um683


How to create and send someone a patch

git diff changes.patch
git apply changes.patch


How to update submodules

git submodule update --init --recursive

If you even get a dirty submodule, cd into it and undo all checkouts

git checkout .


How to reset branch

git reset --hard


How to setup global ignore

git rm --cached .DS_Store
echo .DS_Store >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global


How to untrack a git file (i.e. get gitignore to ignore it if already tracked)

git rm --cached filename


How to compare branch to master

git diff --name-status master dev/saveSongTour


Revert to an early version in git

$ git log
$ git reset --hard SHA1_HASH
$ git push --force -n (test push)
$ git push --force


Undo checkout individual file

$ git checkout -- filename


export repos

git checkout-index -a -f --prefix=/destination/path/
git checkout-index -a -f --prefix=/Users/jr/Downloads/temp/

Note: double — dash on prefix


Multiple branches to find bug

git checkout -b aNewBranch1 SHA1 (test)
git checkout -b aNewBranch2 SHA2 (test)
git checkout -b aNewBranch3 SHA3 (got it!)

git branch -D aBranchToDelete
git difftool branch1 branch2



git tag v1.0
git push origin master v1.0
git checkout -b version1 v1.0
git tag

# To tag a branch do the same thing but push to the remote
git tag foo
git push origin soln foo


Reset the repos

git checkout ferrari
git reset --hard origin/master
git push --force


Create new remote branchs

git branch bmw
git checkout bmw
git push --set-upstream origin bmw


Dirty files that won’t go away

rm -rf components/GLUE
git checkout components/GLUE


Create new remote branch off existing one

git push origin ferrari:ferrari-nov2014
git push origin head:delorean-inter-app-protocol -u


Misc commands

git branch -vv
git branch -a

How to delete a remote branch

git push origin --delete <branch_name>

How to checkout someone elses remote branch

git remote add jr
git fetch jr branch
git checkout branch

At this point you can either merge it to your own local branch

git merge player_state_notifications

Or make modifications directly on it and create pull requests and merge back.


How to update a forked repos
First make sure you have upstream setup from which to pull from. Then

git fetch upstream
git checkout master (your master)
git rebase upstream/master
git push

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: