Reputation: 193
This seems like a really basic operation, but I haven't been able to find a conclusive answer to it.
I often locally create a new branch like this:
git checkout -b new_feature
Then later, I create a remote branch through something like bitbucket or gitlab and want to link my local branch to that newly created remote.
I know i can push to that remote via:
git push origin new_feature:bitbucket_branch_name
But I find this tedious and wonder if there's a more elegant solution to this, eg. set the remote branch to track once and work with classic git pull/git push
from then onward.
Upvotes: 0
Views: 55
Reputation: 2624
You can set the remote origin by
git remote set-url origin bitbucket_url
verify by
git remote -v
Next set branch by
git branch -u bitbucket_branch_name/local_branch_name
From then on git pull/push works with that as default, i.e. no url needed.
Upvotes: -1
Reputation: 72177
The command you are looking for is:
git branch --set-upstream-to=origin/bitbucket_branch_name new_feature
Read more about git branch --set-upstream-to
.
Upvotes: 3