Reputation: 5489
Let's say I have:
I want to push 'branch-A' to 'remote-A/branch-A' without specifying the remote name, and without git checkout branch-A
.
How?
Obviously the following would work:
git push remote-A branch-A
But I really want to omit the 'remote-A' part.
Upvotes: -1
Views: 51
Reputation: 13582
You can set push.default to matching
and shorten the remote name:
git remote rename remote-A rmt-A
git remote rename remote-B rmt-B
Now you can just
git push rmt-A # pushes only branch-A
git push rmt-B # pushes only branch-B
This assumes that you do not have branch branch-A
on remote-B
nor branch-B
on remote-A
.
Upvotes: 1
Reputation: 52081
Technically, the remote name and remote ref name are stored in your local configuration:
$ git config --get branch.branch-A.remote
remote-A
$ git config --get branch.branch-A.merge
refs/heads/that/awful/remote/branch/name
Here is a basic script to get the arguments you want for git push
:
#/bin/bash
branch=$1
remote=$(git config --get config."$branch".remote)
remote_ref=$(git config --get config."$branch".merge)
if [ -z "$remote_ref" ]; then
echo "*** branch '$branch' has no upstream branch defined, cannot push" >&2
exit 1
fi
echo "# pushing to $remote $remote_ref ..."
git push "$remote" "$branch":"$remote_ref"
If you name this script git-pushx
(<- a name starting with git-
, and ending with whatever you want), and place it on your PATH
, you can then type:
$ git pushx branch-A
$ git pushx branch-B
Upvotes: 2
Reputation: 100
You can set push.default
to upstream like
git config --global push.default upstream
and then, git push branch-A
should work.
Upvotes: -1