Skip to content

Instantly share code, notes, and snippets.

@Fireforge
Created December 22, 2019 03:13
Show Gist options
  • Save Fireforge/c363895679b4606666de16e90bb3e593 to your computer and use it in GitHub Desktop.
Save Fireforge/c363895679b4606666de16e90bb3e593 to your computer and use it in GitHub Desktop.
Git Cheatsheet
# Update all the submodules to the latest version:
git submodule foreach git pull origin master
# Prune a git repo of all folders EXCEPT the listed ones
git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- apps/AAA libs/XXX' --prune-empty -- --all
# Remove all empty commits, but keep the commit info (author, date, etc.)
git filter-branch --prune-empty --parent-filter \
'sed "s/-p //g" | xargs -r git show-branch --independent | sed "s/\</-p /g"'
#Git command to multiple dirs:
git add .; git commit -m "Removed unecessary dependencies and moved to snapshots"; git push origin master
ls -Directory -Exclude *-build,.* | ForEach-Object {Push-Location $_; "### $($_.Name) ###"; git --no-pager diff; Pop-Location }
# Get hash of current commit
git rev-parse --short HEAD
# Set up global gitignore
touch ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
# Enable credential cache, helps repeat user/pass prompts, esp. from git-lfs
git config --global credential.helper cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment