One Command for Adding and Pushing Git Remotes
Ever found yourself lost in the repetitive chore of adding a remote and doing that initial push in Git? What if I told you that you could snap those several steps into one magic little command? Well, brace yourself because that's exactly what we're diving into today. By the end of this setup, you’ll be skipping through your Git setup with glee, leaving more precious moments for the actual coding.
Introducing: gr
Meet gr
—short for “Git Remote.” This nifty function is your new best friend. It flawlessly marries the act of adding a remote repository with pushing your local branch up and declaring it as the official upstream branch. The beauty of gr
is how it simplifies your workflow, shaving off precious seconds and boosting your efficiency.
For the Fish Shell Aficionados
Pop this into your ~/.config/fish/config.fish
:
function gr
git remote add origin $argv[1]
if set -q argv[2]
set branch $argv[2]
else
set branch master
end
git push -u origin $branch
end
Zsh and Bash Crew, I've Got You Covered
Slide this into your ~/.zshrc
or ~/.bashrc
:
gr() {
git remote add origin $1 && git push -u origin ${2:-master}
}
Don’t forget to give your shell a quick refresh with source
or simply restart your terminal to usher in the magic.
How to Wave the Magic Wand
Just summon gr
followed by the repository URL and, if you feel like it, tag along the branch name (it’ll default to master if you leave it out):
gr <repository_URL> [branch_name]
With the gr
spell at your fingertips, you’re equipped to breeze through setting up your remote repositories and laying down your main branch without breaking a sweat. It’s all about making your life a tad easier, proving that sometimes, the smallest tweaks make the most significant impact on our development journey.
Embrace gr
, and watch as it turns those dreaded, repetitive git setups into a thing of the past!