Created
April 27, 2026 13:28
-
-
Save JRRS1982/fef3b7c595412f29d95ddfe938c07f3d to your computer and use it in GitHub Desktop.
git-alias.sh
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
| # WHAT: Create a commit with the branch name as a prefix | |
| # WHY: Save yourself some time when creating a commit and reduce errors by automating the addition of the branch name | |
| # HOW: i.e. "gc add a new something" on branch ABC-123 will create a commit "ABC-123: add a new something" | |
| # Remove existing alias if any | |
| unalias gc 2>/dev/null | |
| gc() { | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| git commit -m "$branch: $*" | |
| } | |
| # WHAT: Create a commit with the branch name as a prefix and don't run the pre commit hooks | |
| # WHY: Sometimes you don't need to run the pre-commit hooks as your change does not warrant running them | |
| # HOW: i.e. "gcn update something trivial" | |
| # Remove existing alias if any | |
| unalias gcn 2>/dev/null | |
| gcn() { | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| git commit -n -m "$branch: $*" | |
| } | |
| # WHAT: a function that will push the local branch to the remote origin | |
| # WHY: makes life a little easier by reducing typing. | |
| # HOW: i.e. "gp" | |
| # Remove existing alias if any | |
| unalias gp 2>/dev/null | |
| # Declare a new helper | |
| gp() { | |
| # Get the current branch name | |
| local branch=$(git rev-parse --abbrev-ref HEAD) | |
| # Check if the branch exists on the remote | |
| if git ls-remote --exit-code --heads origin "$branch" &>/dev/null; then | |
| echo "Branch '$branch' already exists on the remote. Pushing updates..." | |
| else | |
| echo "Branch '$branch' does not exist on the remote. Creating it now..." | |
| fi | |
| git push --set-upstream origin "$branch" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment