Skip to content

Instantly share code, notes, and snippets.

@kristofferh
Last active October 12, 2015 02:38
Show Gist options
  • Save kristofferh/3959037 to your computer and use it in GitHub Desktop.
Save kristofferh/3959037 to your computer and use it in GitHub Desktop.
Random git commands

Helpful Git Commands

A random collection of git commands that were helpful to me, and might be helpful to you.

Search commits

git log --grep="search query"

List branches

List local branches that have been merged into master

git branch --merged master

List remote branches that have been merged into master

git branch -r --merged master

Deleting branches

Delete local branch

git branch -D <branchname>

Delete remote branch

git push origin :<branchname>

Misc commands and scripts

Show git branches by date

for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r

Add as command by adding creating bash script (without .sh) in

/usr/local/bin/git-branch-dates

#!/bin/bash
for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r

Git automatically searches through any bash scripts on your path that start with git- so you can now run:

git branch-dates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment