Skip to content

Instantly share code, notes, and snippets.

@sbmadhav
Created September 22, 2020 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbmadhav/ff37aea728043bcd370e2c9b5fd0eaee to your computer and use it in GitHub Desktop.
Save sbmadhav/ff37aea728043bcd370e2c9b5fd0eaee to your computer and use it in GitHub Desktop.
Life saver git commands

Delete branches that did not receive commits more than 4 weeks

    for k in $(git branch | sed /\*/d); do 
      if [ -n "$(git log -1 --since='12 weeks ago' -s $k)" ]; then
        git branch -D $k
      fi
    done

Log branches in order of commits received

    for branch in `git branch -r | grep -v HEAD`; do 
        echo -e `git show --format="%ci %cr %(committerdate) %09 %(authorname) %09 %(refname)" $branch | head -n 1` \\t$branch; 
    done | sort -r

Log branches with creators names

    git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort

Revert a commit after git push

    git push -f origin last_known_good_commit:branch_name
Copy link

ghost commented Apr 23, 2021

The reverting commits is useful to me.

@sbmadhav
Copy link
Author

@GrpeApple Glad it helped you!

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