Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set upstream branch in git-svn?

While working on a usual git repository a local branch usually tracks a corresponding remote upstream branch. This way I can easily see, whether I am ahead or behind of my upstream branch and therefore if I need to push or pull to bring them in sync. Also my prompt immediately shows this state, which is very convenient.

Now I am working on a SVN repository using git-svn. I used --prefix=svn for the clone, therefore git branch -r lists svn/trunk as a remote branch, but (although git svn rebase works without problems) it is not configured as an upstream branch for my master branch.

I tried to set the tracking information manually but it failed:

$ git branch -r
  svn/trunk
$ git branch --set-upstream-to=svn/trunk
fatal: Cannot setup tracking information; starting point 'svn/trunk' is not a branch.

Is there some way to track an svn upstream branch?

Is there some other easy way to know whether I am ahead or behind to that branch? (Looking at gitk --all is currently the only way I am aware of.)

Is there even some way to make my (bash __git_ps1) prompt show that information?


$ git --version
git version 1.9.0.msysgit.0
like image 669
michas Avatar asked Mar 06 '14 15:03

michas


People also ask

How do I set up upstream as a branch?

The easiest way to set the upstream branch is to use the “git push” command with the “-u” option for upstream branch. Alternatively, you can use the “–set-upstream” option that is equivalent to the “-u” option. As an example, let's say that you created a branch named “branch” using the checkout command.

What is -- set upstream in git?

Git set-upstream. The git set-upstream allows you to set the default remote branch for your current local branch. By default, every pull command sets the master as your default remote branch.

How do I set up Forstream without pushing?

Set Upstream If you don't want to push anything, you can also do it using git-branch command. A local branch can track a remote branch using git-branch with long option --set-upstream-to=<upstream> or short option -u <upstream> . The command sets up branchname 's tracking information.

How do I clone a branch in SVN?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...


2 Answers

This seems to be a bug introduced in git 1.9, since --set-upstream-to worked before exactly as you mention.
And strace displays correct locating and reading of the upstream branch ref, then however it's ignored for some reason.


My workaround for this issue is manual editing of .git/config:

$ cat >> .git/config << EOF

[branch "master"]
        remote = .
        merge = refs/svn/trunk
        rebase = true
EOF

— which should be equivalent to:

git branch --set-upstream-to=svn/trunk master

&& git config branch.master.rebase true (which you'll want with svn anyway)

— but is not, because of a bug! "Of course my refs/svn/trunk is a branch!" you say, and edit the config directly (with just a little bit of gentle force).

Your svn trunk could be named differently in git depending on how you cloned the repo (-s, -T, --prefix options to git svn clone). Just do a git branch -avv and find the correct one. For example, one possible name is refs/remotes/git-svn; or refs/svn/trunk as above; or even something else.


Update Nov 2015

I still reproduce this on git version 2.1.4. Anyone to bother file a bug report?

like image 158
ulidtko Avatar answered Oct 28 '22 20:10

ulidtko


This was still a problem for me using git 1.9.5.

And I did not get any of the solutions mentioned here to work, but this worked:

git rebase origin/remote-branch-name

After that git svn dcommit -n shows that it will indeed commit to that svn branch.


Update: I had the same problem again and this time the above didn't work. I just got the message: Current branch master is up to date. However using:

git rebase -i origin/remote-branch-name

forced the rebase anyway and after that the upstream was set correctly.

like image 23
Zitrax Avatar answered Oct 28 '22 21:10

Zitrax