0

Consider this screenshot from our development repository:

Branching

We are relatively new to git, so things are still somewhat confusing. The question at hand: If you take a look at the commits by me at the very top; are confusing to us. Why do I need to merge something if I didn't even branch anything?

I commited the adjust buildpath commit, and after that, git immediately made me do a merge. but with what? The invitation branch is not interesting for me, and I never touched it in any way.

Where did this anonymous blue branch come from and why? My colleague (blue avatar) only works in the invitation branch currently.

Can someone explain to me why this is happening in git-layman terms (as I said, we are new to this)?

  • recommended reading: Where does my git question go? – gnat Aug 15 '14 at 11:11
  • Did you then push the commit dev repository? – Holloway Aug 15 '14 at 11:25
  • @gnat Do you mean to say this is the wrong place or is that just a common comment for any git question? – F.P Aug 15 '14 at 11:26
  • @Trengot I mostly commit immediately, yes – F.P Aug 15 '14 at 11:30
  • per my reading of that guidance this appears to be a question for SO – gnat Aug 15 '14 at 11:35
3

I find the site Visualizing Git Concepts with D3 very helpful to see how the tree will look when various git commands are done from various states.

Lets back track to the Disabled mail delivery... commit.

The next commit was on the invitation branch done by Red as origin/master was merged into that.

Unfortunately teal was still on the master branch and did two commits on master - Removed duplicate imports... and Moved user routes... which were then merged into invitation again by red.

Now, you were also working on what you had locally as master and did the adjust buildpath commit. However, when trying to push this some where it said that your master was out of sync with the remote - and it was. Master on remote was at Moved user routes and thus you had to merge the remote back into what you had.

git merge also does a commit when it does its merge.

From the D3 link at the top, the git merge is very close to the state you had at the adjust buildpath commit. Doing git merge master in your tree is much like doing a git merge dev in the D3 sandbox:

Initial state

And then a git merge dev brings us to:

enter image description here

Commit e065536... is exactly like your Merge branch 'master' of https://... in this case.

But what if you don't want to have those commits. Some people don't like them (personally, I do... but that is my preference).

Then, you are looking at git rebase

This will reapply the commits from one branch on another.

Initial state

Note again the very similar structure as the merge example (note: I've checked out master rather than leave it on dev). And then a git rebase dev brings everything into line without the additional commit.

After rebase

Note that the commit bb92e0e which was the old master head is now greyed out and the new master head is decfd13 because the history is reapplied on top of what you have done.

There's a gotcha there. You are rewriting your local history when you do a rebase. If you have shared the state of your repo (pushing it to somewhere else) where commit bb92e0e is out there, rebasing will confuse everyone. If you have to do a git push --force, you're probably doing it wrong.

Note that when you do a git pull, you are doing the commands git fetch and git merge - thus the additional commit. You can do a git pull --rebase which will be a rebase rather than a merge for the second step (you can also tweak your git config to do this by default). You can play with this a bit in the D3 site 'git pull' example.

Note that the convention on your tree appears to be pull and merge rather than rebase - it may be best to keep following that convention and just understand (and accept) where the commits are coming from.

0

Short answer in git layman terms: your teal colleague is mistaken if they think they were only working on the 'invitation' branch. They were committing + pushing to master, and only then merging back to invitation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.