Two new shell aliases for git

Recently I added two new bash/zsh aliases to make my git experience just a tad better.

trackme

Most of our work repos were recently migrated to new remote urls, we scriped out the update to all of the repos, but I was left with a tracking e…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Waylon Walker

Recently I added two new bash/zsh aliases to make my git experience just a tad better.

trackme

Most of our work repos were recently migrated to new remote urls, we scriped out the update to all of the repos, but I was left with a tracking error for all of my open branches. To easily resolve this I just made an alias so that I can just run trackme anytime I see this error.

There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream develop origin/<branch>

getting the branch

The following command will always return the currently checked out branch name.

git symbolic-ref --short HEAD

Injecting this into the suggested git command as a subshell gives us this alias that when ran with trackme will automatically fix tracking for my branch.

alias trackme='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'

rebasemain

I sometimes get a bit lazy at checking main for changes before submitting any prs, so again I made a quick shell alias that will rebase main into my branch before I open a pr.

alias rebasemain='git pull origin main --rebase'

The Aliases

Here are both of the alias's, feel free to steal and modify them into your dotfiles. If you are uniniatiated a common starting place to put these is either in your ~/.bashrch or ~/.zshrc depending on your shell of choice.

alias trackme='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD)'
alias rebasemain='git pull origin main --rebase'


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Waylon Walker


Print Share Comment Cite Upload Translate Updates
APA

Waylon Walker | Sciencx (2022-09-14T14:28:42+00:00) Two new shell aliases for git. Retrieved from https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/

MLA
" » Two new shell aliases for git." Waylon Walker | Sciencx - Wednesday September 14, 2022, https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/
HARVARD
Waylon Walker | Sciencx Wednesday September 14, 2022 » Two new shell aliases for git., viewed ,<https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/>
VANCOUVER
Waylon Walker | Sciencx - » Two new shell aliases for git. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/
CHICAGO
" » Two new shell aliases for git." Waylon Walker | Sciencx - Accessed . https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/
IEEE
" » Two new shell aliases for git." Waylon Walker | Sciencx [Online]. Available: https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/. [Accessed: ]
rf:citation
» Two new shell aliases for git | Waylon Walker | Sciencx | https://www.scien.cx/2022/09/14/two-new-shell-aliases-for-git/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.