Last active
December 22, 2025 09:46
-
-
Save rocky-jaiswal/c28a17c760a8a791dda31fe8c10fbd03 to your computer and use it in GitHub Desktop.
git helpers
This file contains hidden or 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
| # source /home/rockyj/.config/fish/functions/git_helpers.fish | |
| # Quick status | |
| function gst | |
| git status -sb | |
| end | |
| # Quick add all | |
| function gadd | |
| git add . | |
| echo "✓ All changes staged" | |
| git status -sb | |
| end | |
| # Quick commit with message | |
| function gc | |
| if test (count $argv) -eq 0 | |
| echo "Usage: gc 'commit message'" | |
| return 1 | |
| end | |
| git commit -m "$argv" | |
| end | |
| # Add all and commit | |
| function gac | |
| if test (count $argv) -eq 0 | |
| echo "Usage: gac 'commit message'" | |
| return 1 | |
| end | |
| git add . | |
| git commit -m "$argv" | |
| echo "✓ Committed all changes" | |
| end | |
| # Quick push to current branch | |
| function gpush | |
| set branch (git branch --show-current) | |
| echo "Pushing to $branch..." | |
| git push origin $branch | |
| end | |
| # Quick pull with rebase | |
| function gpull | |
| set branch (git branch --show-current) | |
| echo "Pulling (rebase) to $branch..." | |
| git pull origin $branch --rebase | |
| end | |
| # checkout | |
| function gco | |
| if test (count $argv) -eq 0 | |
| echo "Usage: gco branch-name OR gco -b new-branch-name" | |
| return 1 | |
| end | |
| if test "$argv[1]" = "-b" | |
| if test (count $argv) -lt 2 | |
| echo "Error: Branch name required after -b" | |
| return 1 | |
| end | |
| git checkout -b $argv[2] | |
| echo "✓ Created and switched to branch: $argv[2]" | |
| else | |
| git checkout $argv[1] | |
| echo "✓ Switched to branch: $argv[1]" | |
| end | |
| end | |
| # Show git log in a nice format | |
| function gl | |
| git log --oneline --graph --decorate --color -10 | |
| end | |
| # Show all git log | |
| function gla | |
| git log --oneline --graph --decorate --color --all -20 | |
| end | |
| # Undo last commit but keep changes | |
| function gundo | |
| git reset --soft HEAD~1 | |
| echo "✓ Last commit undone, changes kept in staging" | |
| end | |
| # Discard all local changes | |
| function greset | |
| echo "⚠️ This will discard ALL local changes!" | |
| read -P "Are you sure? (y/n): " confirm | |
| if test "$confirm" = "y" | |
| git reset --hard HEAD | |
| git clean -fd | |
| echo "✓ All changes discarded" | |
| else | |
| echo "Cancelled" | |
| end | |
| end | |
| # Show diff of unstaged changes | |
| function gdiff | |
| git diff | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment