I use the following command to push to my remote branch:
git push origin sandbox
If I say
git push origin
Rather than using aliases, I prefer creating git-XXX scripts so I can source control them more easily (our devs all have a certain source controlled dir on their path for this type of thing).
This script (called git-setpush
) will set the config value for remote.origin.push
value to something that will only push the current branch:
#!/bin/bash -eu
CURRENT_BRANCH=$(git branch | grep '^\*' | cut -d" " -f2)
NEW_PUSH_REF=HEAD:refs/for/$CURRENT_BRANCH
echo "setting remote.origin.push to $NEW_PUSH_REF"
git config remote.origin.push $NEW_PUSH_REF
note, as we're using Gerrit, it sets the target to refs/for/XXX
to push into a review branch. It also assumes origin is your remote name.
Invoke it after checking out a branch with
git checkout your-branch
git setpush
It could obviously be adapted to also do the checkout, but I like scripts to do one thing and do it well