Skip to content

Instantly share code, notes, and snippets.

@chrismccoy
Last active October 24, 2025 12:31
Show Gist options
  • Save chrismccoy/8775224 to your computer and use it in GitHub Desktop.
Save chrismccoy/8775224 to your computer and use it in GitHub Desktop.

Revisions

  1. chrismccoy revised this gist Oct 24, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # release alias with tagging
    # usage: git release v2.3.0 "Finalized API and added documentation" ./docs.zip
    release = !f() { tag="$1"; title="$2"; shift 2; gh release create "$tag" --target $(git rev-parse HEAD) -t "$title" --generate-notes "$@"; }; f

    # usage gh lockdown
    # git alias to disable wikis, issues, projects for existing repos
    lockdown = !f() { gh repo edit "$@" --enable-issues=false --enable-wiki=false --enable-projects=false; }; f
  2. chrismccoy revised this gist Oct 22, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # usage gh lockdown
    # git alias to disable wikis, issues, projects for existing repos
    lockdown = !f() { gh repo edit "$@" --enable-issues=false --enable-wiki=false --enable-projects=false; }; f

    # git alias to set predefined parameters with gh repo create command (disable issues, wikis, and projects)
    # usage: gh rpc myproject --private or gh rpc myproject --description "Passing Another Parameter"
    rpc = !f() { gh repo create "$@" --disable-issues --disable-wiki && gh repo edit "$1" --enable-projects=false; }; f
  3. chrismccoy revised this gist Oct 22, 2025. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # git alias to set predefined parameters with gh repo create command
    # usage: git rpc myproject or rpc myproject --description "Passing Another Parameter"
    rpc = !f() { gh repo create "$@" --private --disable-issues --disable-wiki; }; f
    # git alias to set predefined parameters with gh repo create command (disable issues, wikis, and projects)
    # usage: gh rpc myproject --private or gh rpc myproject --description "Passing Another Parameter"
    rpc = !f() { gh repo create "$@" --disable-issues --disable-wiki && gh repo edit "$1" --enable-projects=false; }; f

    # delete all repos with 1 per line in a text file in powershell
    Get-Content .\repos-to-delete.txt | ForEach-Object { gh repo delete $_ --yes }
  4. chrismccoy revised this gist Oct 20, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # git alias to set predefined parameters with gh repo create command
    # usage: git rpc myproject or it rpc myproject --description "Passing Another Parameter"
    # usage: git rpc myproject or rpc myproject --description "Passing Another Parameter"
    rpc = !f() { gh repo create "$@" --private --disable-issues --disable-wiki; }; f

    # delete all repos with 1 per line in a text file in powershell
  5. chrismccoy revised this gist Oct 20, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # git alias to set predefined parameters with gh repo create command
    # usage: git rpc myproject or it rpc myproject --description "Passing Another Parameter"
    rpc = !f() { gh repo create "$@" --private --disable-issues --disable-wiki; }; f

    # delete all repos with 1 per line in a text file in powershell
    Get-Content .\repos-to-delete.txt | ForEach-Object { gh repo delete $_ --yes }

  6. chrismccoy revised this gist Oct 19, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # delete all repos with 1 per line in a text file in powershell
    Get-Content .\repos-to-delete.txt | ForEach-Object { gh repo delete $_ --yes }

    # delete all private repos (this can not be undone)
    gh repo list --limit 1000 --json isPrivate,nameWithOwner | jq -r '.[] | select(.isPrivate == true) | .nameWithOwner' | xargs -n 1 gh repo delete --yes

  7. chrismccoy revised this gist Oct 19, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # delete all private repos (this can not be undone)
    gh repo list --limit 1000 --json isPrivate,nameWithOwner | jq -r '.[] | select(.isPrivate == true) | .nameWithOwner' | xargs -n 1 gh repo delete --yes

    # delete all git history and keep current as the first commit (this will remove all git history, be careful)
    git reset --soft $(git rev-list --max-parents=0 HEAD) && git commit --amend -m "Initial commit" && git push --force

  8. chrismccoy revised this gist Sep 30, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # delete all git history and keep current as the first commit (this will remove all git history, be careful)
    git reset --soft $(git rev-list --max-parents=0 HEAD) && git commit --amend -m "Initial commit" && git push --force

    # transfer all git repos from one org to another org
    gh repo list {orgname} --limit 300 --json nameWithOwner -q '.[].nameWithOwner' | xargs -I {} gh api --method POST repos/{}/transfer -f new_owner={neworg}

  9. chrismccoy revised this gist Jun 29, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # transfer all git repos from one org to another org
    gh repo list {orgname} --limit 300 --json nameWithOwner -q '.[].nameWithOwner' | xargs -I {} gh api --method POST repos/{}/transfer -f new_owner={neworg}
    gh repo list {orgname} --limit 300 --json nameWithOwner -q '.[].nameWithOwner' | xargs -I {} gh api --method POST repos/{}/transfer -f new_owner={neworg}

    # aliases to change a git repo from private to public, and public to private using gh-cli
    alias gitpublic="gh repo edit --accept-visibility-change-consequences --visibility public"
  10. chrismccoy revised this gist Jun 29, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # transfer all git repos from one org to another org
    gh repo list {orgname} --limit 300 --json nameWithOwner -q '.[].nameWithOwner' | xargs -I {} gh api --method POST repos/{}/transfer -f new_owner={neworg}

    # aliases to change a git repo from private to public, and public to private using gh-cli
    alias gitpublic="gh repo edit --accept-visibility-change-consequences --visibility public"
    alias gitprivate="gh repo edit --accept-visibility-change-consequences --visibility private"
  11. chrismccoy revised this gist Feb 27, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # aliases to change a git repo from private to public, and public to private using gh-cli
    alias gitpublic="gh repo edit --accept-visibility-change-consequences --visibility public"
    alias gitprivate="gh repo edit --accept-visibility-change-consequences --visibility private"

    # delete all your repos using gh-cli (please do not run this unless you want to delete all your repos)
    gh repo list --limit 300 --json url -q '.[].url' | xargs -n1 gh repo delete --yes

  12. chrismccoy revised this gist Feb 26, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # delete all your repos using gh-cli (please do not run this unless you want to delete all your repos)
    gh repo list --limit 300 --json url -q '.[].url' | xargs -n1 gh repo delete --yes

    # make a private git repo public that is private with gh cli
    gh repo edit --accept-visibility-change-consequences --visibility public

  13. chrismccoy revised this gist Feb 4, 2025. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # make a private git repo public that is private with gh cli
    gh repo edit --accept-visibility-change-consequences --visibility public

    # sort list of git repos with gh cli
    gh repo list --limit 300 --json name -q '.[].name' | sort

  14. chrismccoy revised this gist Oct 16, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # sort list of git repos with gh cli
    gh repo list --limit 300 --json name -q '.[].name' | sort

    # count total commits in a repo
    git rev-list --all --count

  15. chrismccoy revised this gist Jun 18, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    # example: git reword commithash message
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # count total commits in a repo
    git rev-list --all --count

    # edit all commit messages
    git rebase -i --root

  16. chrismccoy revised this gist Apr 9, 2024. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    # alias to edit commit messages without using rebase interactive
    # example: git reword commithash message
    git config --global alias.reword '!f() {
    GIT_SEQUENCE_EDITOR="sed -i 1s/^pick/reword/" GIT_EDITOR="printf \"%s\n\" \"$2\" >" git rebase -i "$1^";
    }; f'
    reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"

    # edit all commit messages
    git rebase -i --root
  17. chrismccoy revised this gist Apr 9, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    # alias to edit commit messages without using rebase interactive
    # example: git reword commithash message
    git config --global alias.reword '!f() {
    GIT_SEQUENCE_EDITOR="sed -i 1s/^pick/reword/" GIT_EDITOR="printf \"%s\n\" \"$2\" >" git rebase -i "$1^";
    }; f'

    # edit all commit messages
    git rebase -i --root

  18. chrismccoy revised this gist Apr 8, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # edit all commit messages
    git rebase -i --root

    # clone all your repos with gh cli tool
    gh repo list --json name -q '.[].name' | xargs -n1 gh repo clone

  19. chrismccoy revised this gist Nov 20, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # clone all your repos with gh cli tool
    gh repo list --json url | jq -r '.[].url' | xargs -n1 gh repo clone
    gh repo list --json name -q '.[].name' | xargs -n1 gh repo clone

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r
  20. chrismccoy revised this gist Nov 20, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # clone all your repos with gh cli tool
    gh repo list --json url | jq -r '.[].url' | xargs -n1 gh repo clone

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

  21. chrismccoy revised this gist Aug 9, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

    # zip up an archive of each commit
    for i in `git log --format=%H`; do git archive $i --format=zip -o $i.zip; done

  22. chrismccoy revised this gist Jul 20, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ for i in `git log --format=%H`; do git archive $i --format=zip -o $i.zip; done
    # zip up an archive of each commit
    git rev-list --all | while read h; do git archive --format zip -o $h.zip $h; done

    # zip up an archive of each commit with number of commit added to hash
    git rev-list --all --reverse | while read h; do git archive --format=zip -o commit$((i=i+1))-$h.zip $h; done

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

  23. chrismccoy revised this gist Jul 20, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # zip up an archive of each commit
    for i in `git log --format=%H`; do git archive $i --format=zip -o $i.zip; done

    # zip up an archive of each commit
    git rev-list --all | while read h; do git archive --format zip -o $h.zip $h; done

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

  24. chrismccoy revised this gist Jul 20, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # zip up an archive of each commit
    for i in `git log --oneline --format=%H`; do git archive $i --format=zip -o $i.zip; done
    for i in `git log --format=%H`; do git archive $i --format=zip -o $i.zip; done

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r
  25. chrismccoy revised this gist Jul 20, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # zip up an archive of each commit
    for i in `git log --oneline --format=%H`; do git archive $i --format=zip -o $i.zip; done

    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

  26. chrismccoy revised this gist Apr 10, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # List all files in a folder in a git repository by last commit date
    git ls-tree --name-only HEAD foldername/ | while read filename; do echo "$(git log -1 --format="%ci " -- $filename) $filename"; done | sort -r

    # plot commits per hour
    git log --format=format:'%ai' --all | cut -d " " -f 2 | cut -d ":" -f 1 | sort | uniq -c | gnuplot -e "set output 'commits-per-hour.png'; set term png truecolor giant; set ylabel 'Commits'; set grid y; set boxwidth 0.9 relative; set style fill transparent solid 1.0 noborder; plot '-' using 1:xtic(2) with boxes lc rgb'green' notitle;"

  27. chrismccoy revised this gist Apr 2, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # plot commits per hour
    git log --format=format:'%ai' --all | cut -d " " -f 2 | cut -d ":" -f 1 | sort | uniq -c | gnuplot -e "set output 'commits-per-hour.png'; set term png truecolor giant; set ylabel 'Commits'; set grid y; set boxwidth 0.9 relative; set style fill transparent solid 1.0 noborder; plot '-' using 1:xtic(2) with boxes lc rgb'green' notitle;"

    # list all tags
    git fetch --all --tags --prune

  28. chrismccoy revised this gist Nov 4, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # list all tags
    git fetch --all --tags --prune

    # sort git tags by date
    git for-each-ref --sort=taggerdate --format '%(tag)_,,,_%(taggerdate:raw)_,,,_%(taggername)_,,,_%(subject)' refs/tags | awk 'BEGIN { FS = "_,,,_" } ; { t=strftime("%Y-%m-%d %H:%M",$2); printf "%-20s %-18s %-25s %s\n", t, $1, $4, $3 }'

  29. chrismccoy revised this gist Aug 11, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # sort git tags by date
    git for-each-ref --sort=taggerdate --format '%(tag)_,,,_%(taggerdate:raw)_,,,_%(taggername)_,,,_%(subject)' refs/tags | awk 'BEGIN { FS = "_,,,_" } ; { t=strftime("%Y-%m-%d %H:%M",$2); printf "%-20s %-18s %-25s %s\n", t, $1, $4, $3 }'

    # delete all local tags, and update with list of remote tags
    git tag -l | xargs git tag -d && git fetch -t

  30. chrismccoy revised this gist Jul 5, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # delete all local tags, and update with list of remote tags
    git tag -l | xargs git tag -d && git fetch -t

    # get list of all author's emails of the repo
    git log --format="%ae" | uniq