Last active
December 22, 2022 13:45
-
-
Save aswinsekar/181e7e3913d5447abd401c40bac5f0c1 to your computer and use it in GitHub Desktop.
Git script Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# delete local branches that no longer have remote reference | |
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done | |
# delete files that are being ignored by git(.gitignore) under a directory | |
git clean -xdn # dry run all the files that will list all the gitignore files under the directory | |
git clean -xdf # to clean the files that are ignored | |
# to delete all the files in the git repo, execute the command in the root directory | |
# clone all repos of an org (requires ruby1.9+) | |
curl -s https://api.github.com/orgs/[ORGANIZATION]/repos | ruby -rjson -e 'JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}' | |
# doesn't include private repos | |
# to search a string in all changesets | |
git log -S <string> | |
# Refer https://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string | |
# git log alias | |
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" | |
# called as git lg | |
# git add by hunks | |
git add -p | |
# interactive | |
# list most changed files in the current directory for the past 12 months | |
git log --format=format: --name-only --since=12.month| egrep -v '^$' | sort | uniq -c | sort -nr | head -50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment