Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Using a topic branch with EGit(trying to match up EGit with git-workflow)
Using a topic branch with EGit [message #756237] Fri, 11 November 2011 15:31 Go to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hi there,

I'm looking for suggestions or workflows that can help me use EGit with a modified topic branch workflow. My current usecase for fixing a bug:

1) from master, use Team>Switch To>New Branch to create my topic branch, pwebster/bugXXXX

2) work on my bug

3) commit my fix

4) switch back to master

5) merge from pwebster/bugXXXX

6) delete pwebster/bugXXXX

This works fine, until there are commits on master. If I try an merge into master I get a merge node, which we don't want in our history for basic bug fixes. The problem is I can't tell that I need to rebase my pwebster/bugXXXX branch before I switch to master, because a fetch won't do a FF merge from origin/master to master while I'm on my topic branch.

Do I really need to switch to master, pull, switch back, rebase, switch to master, and keep going?

PW


Re: Using a topic branch with EGit [message #756241 is a reply to message #756237] Fri, 11 November 2011 16:07 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
try the following instead:

* always create new local branches based on origin/master (or whatever remote tracking branch is to be considered upstream for the local branch). Creating local branch based on remote tracking branch establishes a tracking relationship

* set the pull strategy to rebase this will cause pull to do fetch + rebase instead of the standard fetch + merge

* when such a local branch is checked out just run pull, due to the pull strategy "rebase" this will do what you want

* if you always want this pull strategy you may consider to set the config parameter "branch.autosetuprebase" to "always" (either in ~/.gitconfig if you want that for all git repositories or in .git/config of those repositories where you want this)

* I also delete the local master branch as I prefer to always use local branch names reminding me what I am using them for

* if I want to reflect the state e.g. master has on the server in my working tree I simply checkout the remote tracking branch
Re: Using a topic branch with EGit [message #756243 is a reply to message #756241] Fri, 11 November 2011 16:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thanx Matthias, I think branching from origin/master and using the rebase strategy (we do for all tracking branches) will smooth out this workflow for me.

PW


Re: Using a topic branch with EGit [message #756251 is a reply to message #756243] Fri, 11 November 2011 16:33 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I just had a couple of more questions Smile

So if I just do a Push to Upstream from my tracking topic branch, will that then update origin/master (instead of merging into my master and pushing)?

If I need to have a slightly longer lived topic branch and push it to the server, I'll have to abandon my tracking origin/master approach I guess and track my topic branch as the remote branch. Then I'll need to deliberately rebase it on origin/master before my pushes and my local merge, right?

PW


Re: Using a topic branch with EGit [message #756259 is a reply to message #756251] Fri, 11 November 2011 17:11 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Push to upstream will check which branch of which remote your local branch is tracking and then it will use the push refspec defined for this remote.

So if your config would look like

[remote "origin"]
url = git://egit.eclipse.org/egit.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = ssh://pwebster@egit.eclipse.org/egit.git
push = HEAD:refs/heads/master
[branch "test1"]
remote = origin
merge = refs/heads/master
rebase = true
[branch "test2"]
remote = origin
merge = refs/heads/master
rebase = true

Then both local branches test1 and test2 would track the master branch of "origin", i.e. when doing pull EGit would first do a fetch from "git://egit.eclipse.org/egit.git" using the refspec "+refs/heads/*:refs/remotes/origin/*" which would update all remote tracking branches with new changes available on the server and then rebase the currently checked out branch (e.g. test1) onto origin/master (since it's tracking changes from this branch).

When pushing (e.g. when test1 is checked out) EGit would push to "ssh://pwebster@egit.eclipse.org/egit.git" using the push refspec "HEAD:refs/heads/master". This means local changes done on test1 would end up on master on the server.

If you want to choose on a case by case basis where to push a change you may define multiple remotes pointing to the same repository but with different "push" parameter or you may use the Push Wizard where you can define these parameters on the fly.

I don't understand why the lifetime of a local topic branch would require to give up the tracking relationship to origin/master. If you don't always want to rebase changes on a local branch when fetching updates from the server just use "fetch" instead of "pull" this will then only update the remote tracking branch and leave your local branch untouched. You then can do the rebase any time later.

Re: Using a topic branch with EGit [message #756264 is a reply to message #756259] Fri, 11 November 2011 17:43 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Matthias Sohn wrote on Fri, 11 November 2011 12:11

When pushing (e.g. when test1 is checked out) EGit would push to "ssh://pwebster@egit.eclipse.org/egit.git" using the push refspec "HEAD:refs/heads/master". This means local changes done on test1 would end up on master on the server.


I used the workflow you suggested, but seemed to hit a snag. My branch was created like:

[branch "pwebster/bugXXXX"]
remote = origin
merge = refs/heads/master
rebase = true

So far, so good. When I was done, a pull made sure I'm at the tip of origin/master. But the Push to Upstream... from EGit pushed the branch pwebster/bugXXXX to origin instead of updating origin/master on the server.

If I see this behaviour on my next topic branch adventure (so I have exact steps) I'll open a bug. I'm just trying to understand what the desired behaviour would be.

PW


Re: Using a topic branch with EGit [message #756282 is a reply to message #756264] Fri, 11 November 2011 19:02 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Push to origin means you are pushing to the URL given as pushurl (falling back url in case
pushurl isn't defined) defined for this remote using the push configuration defined for that remote.

What's your "push" configuration (refspec) for remote "origin" ?

[remote "origin"]
pushurl = ...
push = ...
Re: Using a topic branch with EGit [message #756295 is a reply to message #756282] Fri, 11 November 2011 19:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I don't have a push spec defined for origin, just:

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=ssh://pwebster@git.eclipse.org/gitroot/platform/eclipse.platform.ui.git

PW


Re: Using a topic branch with EGit [message #756375 is a reply to message #756295] Sat, 12 November 2011 13:49 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
If you don't have a push refspec defined the default is to map branches 1:1 from local branches to branches on the server (beware of bug [1], it may bite you in this case). Usually this is not what you want hence always explicitly define a push refspec [2] for the remote your local branches are tracking branches from to define how to map your local branches to branches on the server when pushing to upstream.

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=352381
[2] http://wiki.eclipse.org/EGit/User_Guide#Direct_Fetch_and_Push_Support
Re: Using a topic branch with EGit [message #756610 is a reply to message #756375] Mon, 14 November 2011 14:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thanx, I'll look into it.

PW


Re: Using a topic branch with EGit [message #756939 is a reply to message #756610] Tue, 15 November 2011 15:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I'm trying to figure out what a good push spec would be. Do I just add multiple push specs to the remote "origin"? ex:

push=pwebster/bug358020:refs/heads/master

PW


Re: Using a topic branch with EGit [message #757041 is a reply to message #756939] Wed, 16 November 2011 08:16 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
I would suggest to use

HEAD:refs/heads/master

Then your currently checked out commit will be pushed to the master branch and you do not need to specify a new push spec for each local feature branch.
Re: Using a topic branch with EGit [message #757104 is a reply to message #757041] Wed, 16 November 2011 14:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That would probably be OK. And if I want to push a feature branch up to the repo (because we'll be working on it for a while), do I have to remove that and go back to per-topic branch push specs?

PW


Re: Using a topic branch with EGit [message #757111 is a reply to message #757104] Wed, 16 November 2011 14:47 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
> do I have to remove that and go back to per-topic branch push specs?

If you have a long living feature branch on the remote repository and you want to work both on that and on master, you could
- add a new remote with the same URL, but the push refspec HEAD:/refs/heads/<featurebranch>, and then you can push only to the feature branch by pushing to that remote
or
- as you suggest, create a push spec for each topic branch. But then, I suppose, all local changes that match the refspecs are pushed at once and you can't easily push only changes relevant for a feature branch if you work in parallel on different features

If the feature branch is not that long living, you could
- in EGit, use the Push... wizard on a repository node. There you can specify the refspec just before pushing. This corresponds to git push <repository> <refspec>. Use the refspec HEAD:/refs/heads/<featurebranch>.
Re: Using a topic branch with EGit [message #757121 is a reply to message #757111] Wed, 16 November 2011 15:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thanx for the information, Stefan,

PW


Re: Using a topic branch with EGit [message #757246 is a reply to message #757121] Thu, 17 November 2011 10:33 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
I think implementing https://bugs.eclipse.org/bugs/show_bug.cgi?id=356314 would also help to make this simpler in case you are using server side feature branches
Previous Topic:How to have the context menu in the History View ?
Next Topic:Branch not present after clone
Goto Forum:
  


Current Time: Thu Mar 28 08:33:16 GMT 2024

Powered by FUDForum. Page generated in 0.04222 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top