Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged git from sorted by
Terminal - Commands tagged git - 97 results
for k in `git branch|sed s/^..//`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k" --`\\t"$k";done|sort
2011-11-02 06:16:22
User: ryan
Functions: echo sed
1

This fixes a bug found in the other scripts which fail when a branch has the same name as a file or directory in the current directory.

git config --local --get remote.origin.url
2011-10-03 09:29:34
User: hced
1

Great way to quickly grasp if a locally cloned repository originates from e.g. github or elsewhere.

git branch | cut -c3- | grep -v "^master$" | while read line; do git branch -d $line; done | grep 'Deleted branch' | awk '{print $3;}' | while read line; do git push <target_remote> :$line; done
2011-08-13 16:58:34
User: gocoogs
Functions: awk cut grep read
0

attempts to delete all local branches. git will fail on any branches not fully merged into local master, so don't worry about losing work. git will return the names of any successfully deleted branches. Find those in the output with grep, then push null repositories to the corresponding names to your target remote.

assumes:

- your local and remote branches are identically named, and there's nothing extra in the remote branch that you still want

- EDIT: you want to keep your local master branch

git add -u
parallel -j4 cd {}\; pwd\; git pull :::: <(git submodule status | awk '{print $2}')
2011-06-20 00:20:26
User: clvv
Functions: awk cd
2

Make sure to run this command in your git toplevel directory. Modify `-j4` as you like. You can also run any arbitrary command beside `git pull` in parallel on all of your git submodules.

git archive HEAD | gzip > ~/Dropbox/archive.tar.gz
git push origin --all
git push origin :featureless
2011-06-02 14:53:31
User: b_t
Tags: git
-1

This will delete the branch 'featureless' on the origin remote.

Do not forget to delete the branch locally using:

git branch -d featureless

'I got it here'-credit:

http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html

I duplicated here incase you stumbled here first.

git ls-files -z -d | xargs -0 git rm --
git log --oneline <REMOTE>..<LOCAL BRANCH>
lynx -dump -nolist http://whatthecommit.com/|sed -n 2p
2011-04-17 17:45:18
User: houghi
Functions: sed
-4

Fetch comical VC commit messages from whatthecommit.com

curl -s http://whatthecommit.com | html2text | sed '$d'
2011-04-14 16:51:53
User: zbeekman
Functions: sed
-1

Requires html2text. Print bad, but often funny commit messages from whatthecommit.com

curl -s http://whatthecommit.com | sed -n '/<p>/,/<\/p>/p' | sed '$d' | sed 's/<p>//'
function where(){ COUNT=0; while [ `where_arg $1~$COUNT | wc -w` == 0 ]; do let COUNT=COUNT+1; done; echo "$1 is ahead of "; where_arg $1~$COUNT; echo "by $COUNT commits";};function where_arg(){ git log $@ --decorate -1 | head -n1 | cut -d ' ' -f3- ;}
2010-12-08 15:41:39
User: noisy
Functions: cut echo head wc
Tags: git
0

usage:

where COMMIT

for instance:

where 1178c5950d321a8c5cd8294cd67535157e296554

where HEAD~5

git status | perl -F'\s' -nale 'BEGIN { $a = 0 }; $a = 1 if $_ =~ /changed but not updated/i; print $F[-1] if ( $a && -f $F[-1] )'
2010-10-15 07:58:14
Functions: perl
Tags: status git perl
0

Parse the output of git status.

Once the line '# Changed but not updated:' has passed print every last part of the line if it exists on disk.

git grep "search for something" $(git log -g --pretty=format:%h -S"search for something")
git log --pretty=format:%H | tail -1
2010-08-17 13:47:42
Functions: tail
Tags: git commit
1

git log --format=%H | tail -1 doesn't work anymore

git log --format=%H | tail -1
2010-07-20 08:12:05
User: l0b0
Functions: tail
Tags: git commit
0

Can anyone make a shorter one?

This doesn't work:

git log --reverse -1 --format=%H
git log --format='%aN <%aE>' | awk '{arr[$0]++} END{for (i in arr){print arr[i], i;}}' | sort -rn | cut -d\ -f2-
2010-07-19 11:40:52
Functions: awk cut sort
Tags: git
2

Gets the authors, sorts by number of commits (as a vague way of estimating how much of the project is their work, i.e. the higher in the list, the more they've done) and then outputs the results.

git archive HEAD --format=zip > archive.zip
zip -r homard homard -x homard/.git\*; cp ./homard.zip /path_to_dropbox_public_folder/homard.zip
2010-06-30 22:19:39
User: juliend2
Functions: cp
Tags: git zip dropbox
-1

If like me you do a lot of front-end coding and you have a lot of clients that asks you some little modifications, then you send the modifications back to them in a zip file while ignoring the .git folder and .gitignore file, then copy this zip into your dropbox and send it back to them. They find out a new bug so, rince and repeat? You get the picture. It can be quite tedious.

git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/'
curl http://github.com/api/v1/yaml/search/vim
2010-05-30 00:29:03
User: rkulla
Tags: git curl github
2

In this example we search for 'vim' but vim doesn't have a project on github right now. That's ok, this command still searches for every project that has 'vim' in their description (forks, plugins, etc). To get XML or JSON output just replace 'yaml' in the url with 'xml' or 'json'.

curl http://github.com/api/v1/yaml/git
2010-05-30 00:18:00
User: rkulla
Tags: git curl github
2

In this example 'git' is the user name and the output format is YAML but you can change this to XML or JSON, eg: curl http://github.com/api/v1/json/usernamehere

git log --all --pretty=format:" " --name-only | sort -u
2010-05-11 16:06:42
Functions: sort
Tags: history git
2

What was the name of that module we wrote and deleted about 3 months ago? windowing-something?

git log --all --pretty=format:" " --name-only | sort -u | grep -i window