views:

52

answers:

1

I am confused with remote branches.

My local repo:

(local) ---A---B---C-master

My remote repo (called int):

(int) ---A---B---C---D---E-master

What I want to do is to setup the local repo's master branch to follow that of int. Local repo:

(local) ---A---B---C---D---E-master-remotes/int/master

So that when int changes to:

(int) ---A---B---C---D---E---F-master

I can run git pull from the local repo's master and get

(local) ---A---B---C---D---E---F-master-remotes/int/master

Here's what I have tried:

  1. git fetch int gets me all the branches of int into remote branches. This can get messy since int might have hundreds of branches.

  2. git fetch int master gets me the commits, but no ref to it, only FETCH_HEAD. No remote branch either.

  3. git fetch int master:new_master works but I don't want a new name every time I update, and no remote branch is setup.

  4. git pull int master does what I want, but there is still no remote branch setup. I feel that it is ok to do so (that's the best I have now), but I read here and there that with the remote setup it is enough with git pull.

  5. git branch --track new_master int/master, as per http://www.gitready.com/beginner/2009/03/09/remote-tracking-branches.html . I get "not a valid object name: int/master". git remote -v does show me that int is defined and points at the correct location (1. worked). What I miss is the int/master branch, which is precisely what I want to get.

  6. git fetch in master:int/master. Well, int/master is created, but is no remote.

So to summarize, I've tried some stuff with no luck. I would expect 2 to give me the remote branch to master in the repo int.

The solution I use now is option 3.

I read somewhere that you could change some config file by hand, but isn't that a bit cumbersome?


The "cumbersome" way of editting the config file did work:

[branch "master"]
    remote = int
    merge = master

It can be done from command line:

$ git config branch.master.remote int

$ git config branch.master.merge master

Any reason why option 2 above wouldn't do that automatically? Even in that case, git pull fetches all branches from the remote.

A: 

Make sure you don't have any current work in your working tree first.

Then try a (with Git1.7.0 or more):

git fetch int master
git branch --force -- set-upstream master int/master
VonC
I get: `fatal: Cannot force update the current branch.` With a bit of trying I got to the point where I have a local tracking branch, but no remote tracking branch (i.e. they show in all green in gitk, no beige'n'green).
Gauthier
@Gauthier: err... but there is no such thing as a *local* tracking branch ;) Only *remote* tracking branch: see http://stackoverflow.com/questions/1070496/having-a-hard-time-understanding-git-fetch
VonC
alright, I might have misunderstood something. What I mean is that when I tried a command that seemed to have an effect, I got: `Branch <branchname> set up to track local branch <int/branchname>.`, and it did not look like a remote.
Gauthier
`git fetch int master` gets the commits and give me `FETCH_HEAD` as a reference. How would the second line you wrote know where to set the upstream?
Gauthier
@Gauthier: not exactly: the second line is to force a local existing branch to follow a remote tracking branch you specify (composed of a remote repo name and a remote tracking branch name). So the second line knows where to set the upstream because you give in this line the exact reference of said upstream.
VonC