ARandomFurry
ARandomFurry

Reputation: 203

Different remote branches for pushing and pulling

Is it possible to git push to branch B, while using git pull to pull from branch A, while the local branch is branch C?

I realize that git pull pulls all the branches down by default, and would be fine with setting it up to only pull the currently checked out branch.

To clarify; the local clone of the repository only has branch C.

git fetch
git pull

For this branch get their commits from remote branch A and

git push

Should send commits upstream to remote branch B.

Upvotes: 2

Views: 152

Answers (2)

apprenticeDev
apprenticeDev

Reputation: 8059

You could write your command more explicitly - this would also ensure you know exactly where commits are coming from or going to.

git push (and pull) by default expand to git push origin current_branch_name, which is a shorthand for git push origin current_branch_name:current_branch_name, where left side of the colon is originating branch and right side is destination branch.

So, for your example, to pull from remote branch A to local branch C, you could do

git pull origin A:C

to push from local branch C to remote branch B -

git push origin C:B

Upvotes: 1

Christoph Sommer
Christoph Sommer

Reputation: 6943

The branch.<name>.pushRemote option was created to simplify the use case you describe: pushing to a different remote than you pull from. The documentation has more details.

Upvotes: 0

Related Questions