0

I have a local git repository with two remotes ('origin' is for internal development, and 'other' is for an external contractor to use). The master branch in my local repository tracks the master in 'origin', which is correct. I also have a branch 'external' which tracks the master in 'other'. The problem I have now is that my master brach ALSO wants to push to the master in 'other' as well, which is an issue. Is there any way I can specify that the local master should NOT push to other/master?

I've already tried updating my .git/config file to include:

[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "external"]
    remote = other
    merge = refs/heads/master
[push]
     default = upstream

But remote show still shows that my master is pushing to both remotes:

toko:engine cmlacy$ git remote show origin
Password: 
* remote origin
  Fetch URL: <REPO LOCATION>
  Push  URL: <REPO LOCATION>
  HEAD branch: master
  Remote branches:
    master              tracked
    refresh-hook        tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Those are all correct.

toko:engine cmlacy$ git remote show other
Password: 
* remote other
  Fetch URL: <REPO LOCATION>
  Push  URL: <REPO LOCATION>
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    external merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

That last section is the problem. 'external' should merge with other/master, but master should NEVER push to other/master. It's never gong to work.

Curtis
  • 3,720
  • 1
  • 16
  • 25

2 Answers2

1

In the .git/config add a parameter push = external:master under the section [remote "other"].

kan
  • 26,120
  • 6
  • 61
  • 96
0

Yes, you can specify where to push, for example:

git push <remote> <local branch name>:<remote branch name>

Doing git help push would have given you that answer, by the way.

EDIT: to do that automatically, you probably want to set up tracking, look at: https://mislav.net/2010/07/git-tips/ and set your push.default to tracking (you might have a look at Configure a local branch for push to specific branch as well)

I hope that solves it :)

Dave Powers
  • 1,510
  • 2
  • 23
  • 26
rks
  • 880
  • 5
  • 12
  • Thanks, but I know I can specify that I want to push to particular branch. I'm looking more for a way to change the default behavior so that I don't HAVE to. – Curtis Sep 05 '12 at 14:36
  • Your second link I've seen - that's where I got the idea of setting push.default to upstream ("tracking" was deprecated in 1.7). And I've set up all the tracking, but I can't seem to get my master branch to "untrack" the master in the 'other' repo. I've edited my question to show my 'git remote show' output. – Curtis Sep 05 '12 at 14:54