#Git Cheatsheet
This is a collection of git
commands that I use frequently. May or may not be useful to you, but it's useful to me, dammit.
#Git Add Interactive Mode
git add -i
#Clone repository / respective branch:
$ git clone -b <branch name> <host>
#Delete Local and Remote Branch
git push origin --delete <branch_name>
git branch -d <branch_name>
#Merge to Master
git checkout master
git pull origin master
git merge --no-ff test
git push origin master
#Merge into some other branch
git checkout production
git merge development
git push origin production
#Create a new branch and push it to the remote repo
git checkout -b myFeature dev
git push origin myFeature
#Stashing Work In Progress (WIP) changes
git stash
And to get it back:
git stash pop
#So you forked a Repo and want to keep your fork updated
git remote add upstream git@github.com:company/projectyourforkedfrom.git
To update:
git fetch upstream
git rebase upstream/master
If you have commit rights to the upstream repo, you can create a local upstream
branch and do work that will go to upstream there.
git checkout -b upstream upstream/master
#Sometimes, you want to locally (or temporarily) ignore a file but don't want to add it to .gitignore
Be careful with this, because if you ignore a file, and then do a git pull
after the file was changed upstream, you'll get a conflict. And you'll be confused because Git will tell you to stash your changes, all the while git status
is showing no changes.
Ignore it:
git update-index --assume-unchanged <file>
Unignore it:
git update-index --no-assume-unchanged <file>