I\'ve been wondering if there\'s an easy way to push and pull a local branch with a remote branch with a different name without always specifying both names.
For exa
I have been running into the same issue for quite sometime now. I finally have a set of statements so I don't have to do git push origin local:remote
every time. I followed these:
git branch --set-upstream-to origin/remote_branch_name
git config push.default upstream
git push
After setting upstream to a remote branch with different name (1st line) and then making that upstream as default (2nd line), 3rd line will now obey these rules and push to the set upstream.
Here's the process that has worked for me.
git clone original-repo-url
git remote rename origin upstream
git remote add origin new-repo-url
Now your new repo will be ‘origin’ and the original repo is ‘upstream’. Confirm it by running git remote -v. (Side note: Upstream is used to fetch from the original repo - in order to keep your local copy in sync with the project you want to contribute to - and origin is used to pull and push since you can contribute to your own repo).
git push origin master
Now your new remote repo's master (on Github) will be in-sync with the original master, but it won't have any of the feature branches.
git rebase upstream/branch-name
git push origin master
Rebase is a smart merge. Then push to master again and you’ll see the selected feature branch as master on the new repo.
Optional:
git remote rm upstream
git remote add upstream new-repo-url
Sure. Just set your push.default
to upstream
to push branches to their upstreams (which is the same that pull
will pull from, defined by branch.newb.merge
), rather than pushing branches to ones matching in name (which is the default setting for push.default
, matching
).
git config push.default upstream
Note that this used to be called tracking
not upstream
before Git 1.7.4.2, so if you're using an older version of Git, use tracking
instead. The push.default
option was added in Git 1.6.4, so if you're on an older version than that, you won't have this option at all and will need to explicitly specify the branch to push to.
The command by Adam is now deprecated. You can use:
git branch --set-upstream-to origin/my_remote_branch my_local_branch
to set the upstream branch of my_local_branch
to origin/my_remote_branch
.
When you do the initial push add the -u parameter:
git push -u origin my_branch:remote_branch
Subsequent pushes will go where you want.
EDIT:
As per the comment, that only sets up pull.
git branch --set-upstream
should do it.