View local commits not in origin/master
git log origin/master..HEAD
Reset local repo back to remote repo head
git reset --hard origin/master
Create a new remote branch called "design"
git push origin design
Push the contents of a local branch into those of a remote branch with a different name
git push origin <local branch name>:<remote branch to push into>
Delete a local branch called "design"
git branch -D design
Delete a remote branch called "design"
git push origin :design
Delete a remote branch called design using refs/head. You may have to do this if you have a tag with the same name as the branch you are trying to delete. i.e. error: dst refspec fix-1-improve-binary-download matches more than one.
git push origin :refs/heads/design
Create a new local branch and switch to it
git checkout -b new-branch
Revert remote repo to local, may be dangerous if others have pulled changes
git push staging master:master --force
Show origin details, shows tracking status of branches
git remote show origin
Set the remote tracking branch for a local
git branch --set-upstream foo upstream/foo
Create a new local branch that tracks an existing remote
git checkout --track -b ${branch_name} origin/${branch_name}
or
git checkout ${branch_name}
Ruby method to get current branch name
def git_branch
`git name-rev --name-only HEAD`
end
Cache login details for 1 hour
git config --global credential.helper "cache --timeout=3600"
Git log on one line: hash, author, date/time, message
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
###Housekeeping
Cleanup files, optimise repo
git gc
Delete all stale tracking branches under "origin"
git remote prune origin
#Do a dry run first
git remote prune -n origin
http://help.github.com/git-cheat-sheets/
###GitHub
https://help.github.com/articles/fork-a-repo
Add original repo as upstream so you can pull updates
git remote add upstream [email protected]:feedhenry/Wufoo-Template.git
git fetch upstream
Clone a remote repo locally, change its name and set a new remote for it. This is handy if you have boilerplate stored in github and want to start a new project. This example uses my angular-seed boilerplate repo.
git clone https://github.com/dmcaodha/angular-seed.git
mv angular-seed/ <project-name>/
cd <project-name>/
rm -rf .git
git init
git add .
git commit -a -m "boilerplate commit"
git remote add origin https://github.com/dmcaodha/<repo-name>.git
git push -u origin master