Skip to content

Instantly share code, notes, and snippets.

@keithshep
Last active September 29, 2020 15:26
Show Gist options
  • Save keithshep/499035 to your computer and use it in GitHub Desktop.
Save keithshep/499035 to your computer and use it in GitHub Desktop.
git cheats
# grep through git history
for i in {1..20}
do
echo "### check master~$((i - 1)) vs master~${i} diff ###"
git diff "master~$((i - 1))" "master~${i}" | grep -i 'sample-index'
done
# merge logs across several projects
(echo "commit time,author,project,message"; \
(for i in `"ls" -d */`; do (cd $i; git log "--pretty=tformat:%ai,%an,$i,%s") 2>/dev/null; done \
| sort --reverse | grep -i shep)) | csvtopretty - | less -S
# initialize submodules after checkout
git submodule init && git submodule update && git submodule foreach 'git checkout master'
# push all sub-modules at once
git submodule foreach 'git push origin master'
# initializing a shared git repo on our server
git init --bare --shared=group
# pushing to repo on server
git push ssh://forge.jax.org/srv/git/heredity-hmm master
# creating a new git submodule using a relative path
git submodule add ../build-common build-common
# setting the origin repo
git remote add origin git@github.com:keithshep/txt-sushi.git
# reset last commit leaving working files untouched
git reset --soft HEAD^
# ... edits ...
git commit -a -c ORIG_HEAD
# where am I relative to tag
git describe
# where am I
git show
# allows you to push to a non-bare repo if you run in server repo (git version >= 2.3)
git config --local receive.denyCurrentBranch updateInstead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment