Felix
Felix

Reputation: 89626

Track branch after creation?

Here's my scenario (it's a very simple one): I have created a branch locally, without using --track. I made a few commits and pushed it like so:

git push origin test

But now I don't want to have to type origin test everytime I push this branch, so I'd like to have it track origin/test (or is it the other way around?).

How can I achieve this? I tried:

git branch --set-upstream origin/test

and it didn't work. When I try to push it says "everything up to date", and it seems to have created an actual branch called "origin/test", which is not what I want.

Update: here are the contents of .git/config (after running --set-upstream):

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@***.unfuddle.***/***.git
    fetch = +refs/heads/*:refs/remotes/unfuddle/*
    push = refs/heads/master:refs/heads/master
[gui]
    wmstate = normal
    geometry = 1098x644+298+187 207 207
[branch "test"]
    remote = origin
    merge = refs/heads/test

Upvotes: 2

Views: 667

Answers (4)

Matt Meng
Matt Meng

Reputation: 850

--set-upstream has been deprecated. Use --track or --set-upstream-to instead.

git branch --track test origin/test

Upvotes: 1

KingCrunch
KingCrunch

Reputation: 132051

You forgot to specifiy the local branch when calling git branch --set-uptstream

git branch --set-upstream test origin/test

Edit: OK, maybe you didn't forget it (because the last argument can be omitted), but you want to set the local branch to track the remote one (manpage git-branch), instead you did the opposite (assuming that you are currently on the branch test)

git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]

You specify, that origin/test track test.

Upvotes: 6

Felix
Felix

Reputation: 89626

I ended up manually editing .git/config. Here's what it looks like now:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@***.unfuddle.***/***.git
    fetch = +refs/heads/*:refs/remotes/unfuddle/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "test"]
    remote = origin
    merge = refs/heads/test

Seems to work now. I got the example from another project where I've set up the branches using --track.

I think the problem lied with the push statement in [remote "origin"], I think that made it always push the master branch.

Upvotes: 0

Aasmund Eldhuset
Aasmund Eldhuset

Reputation: 37990

Try git push -u origin test.

Upvotes: 0

Related Questions