Commands tagged git (122)

  • We had a number of git tags named similarly to: 2016.12.13.devel.feature 2016.12.14.master.release But we have multiple developers making commits and tags for testing purposes. I wanted to reduce the number of tags that displayed on our cloud hosting server when doing a deployment.

    git ls-remote --tags origin | awk '/^(.*)(\s+)(.*)(YOUR-TAG-SPECIFIC-SEARCH-TERM-HERE)(.*)(-+)(.*)[^{}]$/ {print ":" $2}' | xargs git push origin
    shanford · 2017-03-06 21:59:15 0

  • 0
    git commit -m "commit title message" -m "commit body message";
    shaybery · 2017-01-16 21:33:40 0
  • After cloning an empty repository on the client ("git clone" just after "git init", for instance), "git push" fails. In order to be able to push to this repository for the first time, you need to run the above command. It will link your local "master" branch to the "master" branch in the origin server, and push the changes. This is only necessary only for the first push; after that, you can use just the commands "git push" or "git pull" in order to do this operations. Show Sample Output

    git push --set-upstream origin master
    quitaiskiluisf · 2017-01-09 00:32:14 0
  • Do a git commit using a random message. Show Sample Output

    git commit -m "$(curl -s";
    paulera · 2016-05-04 09:51:18 1
  • Useful for looking up and commits that you may have lost during a rebase or when rewriting some history.

    git fsck --lost-found | grep commit | cut -d " " -f 3 | xargs git show -s --oneline
    ghthor · 2016-03-23 17:26:17 0
  • Find in which branch a file is committed. % git log --all -- '**/my_file.png'

    git log --all -- '*RestSessionController*''
    vivek_saini07 · 2016-02-23 20:18:38 0
  • Uses git grep for speed, relies on a valid she-bang, ignores leading whitespace when stripping comments and blank lines Show Sample Output

    egrep -v '^\s*($|#)' $(git grep -l '#!/bin/.*sh' *) | wc -l
    Natureshadow · 2016-02-15 11:15:48 1

  • 0
    for i in $(git log --format='%ae' | sort -u); do echo $i; git log --author="$i" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' - done
    flavioab · 2016-01-27 20:46:51 0
  • 1. No for-loop, but xargs. 2. Append "--" in git-reset HEAD command to deal with filenames contained leading hyphen/minus sign (-). 3. Add "--porcelain" option in git-status command for easy-to-parse format when scripting. 4. Add "--no-run-if-empty" option in xargs command to prevent you run it twice and accidentally reset all staged changes. 5. Use zero byte (NUL character) as line terminator instead of newline (\n) to make it more robust to deal with filename with whitespaces. pipe#1: git-status. pipe#2: Use "grep" to filter out "non-added" files. pipe#3: use "sed" to Trim out the leading three characters, reserve the filename. pipe#4: xargs + git-reset... p.s. The "HEAD" in git-reset can be omitted . And, maybe, the third part of this shell pipe (sed) has potential to be enhanced.

    git status --porcelain -z | grep -zZ '^A[ MD] ' | sed -z 's/^...//' | xargs -0 --no-run-if-empty git reset HEAD --
    goldie · 2016-01-24 16:20:08 0
  • The idea is to get the current branch name directly using git symbolic-ref --short HEAD name and not type it manually. Show Sample Output

    git push --set-upstream origin `git symbolic-ref --short HEAD`
    phoe6 · 2016-01-08 18:23:07 0

  • 0
    for f in `git status | grep new | awk '{print $3}'`; do git reset HEAD $f ; done
    Wafelijzer · 2015-12-16 22:24:34 4
  • This is how you can do this without having to use oneline Show Sample Output

    git log | nl -w9 -v0 --body-numbering='pcommit\ [0-9a-f]\{40\}' | sed 's/^ \+\([0-9]\+\)\s\+/HEAD~\1 /'
    guywithnose · 2015-11-23 21:53:33 0
  • Print a git log (in reverse order) giving a reference relative to HEAD. HEAD (the current revision) can also be referred to as HEAD~0 The previous revision is HEAD~1 then HEAD~2 etc. . Add line numbers to the git output, starting at zero: ... | nl -v0 | ... . Insert the string 'HEAD~' before the number using sed: ... | sed 's/^ \+/&HEAD~/' . Thanks to bartonski for the idea :-) Show Sample Output

    git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'
    flatcap · 2015-11-23 21:35:57 0

  • 1
    o=0; git log --oneline | while read l; do printf "%+9s %s\n" "HEAD~${o}" "$l"; o=$(($o+1)); done | less
    bartonski · 2015-11-23 17:47:16 0
  • Where $1 = author and $2 = mod name You need to be running a daily build of Minetest (for example from the 'minetestdevs/daily-builds' PPA), or some bleeding edge mods will not work or crash the game. Update a mod by entering its subdirectory under ~/.minetest/mods and doing git pull && git submodule update --recursive --remote --init

    cd ~/.minetest/mods && git clone --recursive$1/$2.git
    lordtoran · 2015-09-30 19:24:59 0
  • Normally, searching git log comments is case sensitive. The -i luckily applies to the --grep switch.

    git log -i --grep='needle'
    sudopeople · 2015-08-11 23:07:55 0
  • A great command to assign to an alias, allowing you to git diff the last two commits in git.

    git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")
    caffeinewriter · 2015-07-07 17:50:50 1

  • -2
    for file in $( git ls-files ); do echo $file; touch -t $(git --no-pager log --date=local -1 --format="%ct" $file | php -r 'echo @date( "YmdHi.s", trim( file_get_contents( "php://stdin" ) ) );') $file; done
    westonruter · 2015-07-01 00:28:06 3
  • Creating feature-branches off master, and trying to merge them in an integration branch (preview), sometimes causes conflicts because the feature-branch might hold changes from 'master' that aren't on preview yet. So this ensures only the commits added to the feature-branch are moved to integration (preview). Note: This assumes you're currently on the feature-branch. Adjust 'master/preview' branch names to suit your environment.

    git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done
    shadyvb · 2015-04-23 14:28:06 1

  • -1
    git diff --word-diff --color-words | aha > index.html && firefox index.html
    dlebauer · 2015-04-20 15:24:56 0
  • For editing files added to the index: vim `git diff --name-only --cached` To edit all changed files: vim `git diff --name-only HEAD` To edit changed files matching glob: vim `git diff --name-only -- '*.html'` If the commands needs to support filenames with whitespace, it gets a bit hacky (see for the reason): git diff --name-only -z | xargs -0 bash -c '</dev/tty vim "$@"' x The last part can be put in a script named e.g. vimargs, and used with any command outputting NUL separated filenames: git grep -lz foobar | vimargs

    vim `git diff --name-only`
    mbudde · 2015-02-25 11:12:49 0
  • Delete all your branches except master (useful after archiving branches) Show Sample Output

    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash
    Trindaz · 2015-01-31 00:29:32 2
  • Description by segments delimited by pipe (|) 1. List all git branches 2. Exclude master 3. Trim output and remove display elements such as * next to current branch 4. Repeat branch name after a space (output on each line: branch_name branch_name) 5. Prepend each line with the git tag command 6. Execute the output with bash

    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/.*/& &/' | sed 's/^/git tag archive\//' | bash
    Trindaz · 2015-01-31 00:26:15 0
  • This checks if the branch has been merged with master and then will delete the ones that have been. Keeps your local git repo nice and clean from all the branches. Show Sample Output

    git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
    krizzo · 2015-01-25 00:30:37 0
  • List all dependencies manifests so you can install them. In a scenario where you want to deploy a number of web applications and run their dependency managers, how could you run all of them in a systematic order. One of the complexity is to ensure you get only your own top level dependencies. That way, you don recursively call development dependencies of your own dependencies. Otherwise you might end up discovering dependency management manifests that are already been pulled by your own projects. # Using this command This command helps me find them and I can then run what?s required to pull them from their respective sources. This command assumes the following: 1. Your code checkouts are in a flat repository layout (i.e. not nested). 2. Finds manifests for: - NPM (nodejs), - Composer (php), - bower, - requirements.txt (Python), and - git submodules Show Sample Output

    find /srv/code -maxdepth 4 -type f -regex ".*\(\(package\|composer|npm\\|bower\)\.json\|Gemfile\|requirements\.txt\\|\.gitmodules\)"
    renoirb · 2014-11-28 16:34:35 0
  •  1 2 3 >  Last ›

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

Check These Out

Make vim open in tabs by default (save to .profile)
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.

Clear current session history (bash)

Burn CD/DVD from an iso, eject disc when finished.
cdrecord -scanbus will tell you the (x,y,z) value of your cdr (for example, mine is 3,0,0)

Execute a command at a given time
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.

list files recursively by size

list block devices
Shows all block devices in a tree with descruptions of what they are.

Convert .wma files to .ogg with ffmpeg

Get Dell Service Tag Number from a Dell Machine
This will give you the Dell Service tag number associated with your machine. Incredibly useful when you need that number for tech support or downloads.

Find the package that installed a command

check open ports without netstat or lsof

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.


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: