Reputation: 797
I'd like to set up a git repository in which I can push/pull my changes to/from different locations depending on which branch I am.
The idea is to have two branches:
I assume that with this setup I can easily handle internal/public development on the same project. Now I'm stuck at how to do this. I followed this answer but it seems to me that remote locations can be applied only on a whole repository rather than for separate branches.
How do fix this? If this is not the way to go, please suggest me a best practice.
Upvotes: 0
Views: 339
Reputation: 4626
The long format of git push
is:
git push remotename localbranch:remotebranch
It gives you all the flexibility needed to selectively push branches to desired remotes.
Examples
Push master
branch to origin
git push origin master
Push develop
branch to myfork
git push myfork develop
Push develop
branch to a branch called newbranch
on myfork
git push myfork develop:newbranch
The full syntax with colon can also be used to delete a branch. This deletes newbranch
from myfork
by pushing "nothing" into it
git push myfork :newbranch
I tend to mostly use explicit commands with git rather than relying on some default behavior. Whenever a collegue is stuck on git there's usually a plain git pull
or git push
in his command history which makes me smile (or sigh if I'm in a particularly bad mood).
Since you're also asking for tip, before pushing you might want to look around:
git remote -v
git fetch remotename
git branch -a
Upvotes: 1