Skip to content

Instantly share code, notes, and snippets.

@mogox
Last active March 29, 2016 00:24
Show Gist options
  • Save mogox/9143210 to your computer and use it in GitHub Desktop.
Save mogox/9143210 to your computer and use it in GitHub Desktop.
Git tips(reminders)

Adding a remote

git remote add upstream https://github.com/otheruser/repo.git

List of remotes

git remote -v

git cherry-pick a merge commit

git cherry-pick -m 1 <SHA5> 

git 1.7 squash commits

git merge --squash feature/old_branch

Delete branches already merged

gco master && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

Delete Remote tag

git push origin :refs/tags/tag_name

List branches and show info on last commit

function heads(){
  for k in `git branch | perl -pe s/^..//`; do echo -e `git log --color --pretty=format:"%C(auto)%ad%C(bold green)$k%Creset|%s (%Cgreen%cr%Creset by %C(bold blue)%an%Creset)"  --date=short $k | head -n 1`; done | sort -r | perl -pe s/^[0-9\-]*// | column -t -s '|’
}

List only file names that changed

git diff --name-only SHA1 SHA2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment