2

I am using TortoiseGit v 1.8.9.0 as my client.

I have a git repository with currently has 2 branches. The HEAD branch and also the 1.0.0-Enhancements branch.

enter image description here

The 1.0.0-Enhancements branch is not up to date in my local repository. So when I look at the commit history of this branch on my local using TortoiseGit it does not show the commits on this branch that I can see on the remote in GitWeb.

Here are two screenshots which illustrate that my local copy of the 1.0.0-Enhancements branch is missing commits.

-->History on my local using TortoiseGit enter image description here

-->History of remote on GitWeb enter image description here

My ultimate goal is to merge the 1.0.0-Enhancements branch into the HEAD branch however before I do this I believe that the 1.0.0-Enhancements branch should be up to date on my local.

I have been trying for a couple of hours now to try and find a way to fetch 1.0.0-Enhancements commit from the remote to my local but can't find a way. This is what I tried ...

  1. Make tortoise Git Switch to 1.0.0-Enhancements branch. enter image description here

  2. Use tortoiseGit to fetch from the remote branch. enter image description here

But after doing this when I look at the history of my 1.0.0-Enhancements branch the missing commits are still missing. Can someone help me with how I might fix this?

--Update for answer byt @CupCake--

TortoiseGit also comes with a bash prompt. I tried both your suggestions using the command line but they did not work. Here are the results.

enter image description here enter image description here

But I did seem to make some progress with trying a git pull from the TortoiseGit UI. enter image description here

Which seemed to work except it came back with an error:

git.exe pull -v --progress "origin" 1.0.0-ENHANCEMENTS

From ssh://upredmine/cvs/repo/codeRepository/git/repo04/EPOS/EPOSWeb * branch 1.0.0-ENHANCEMENTS -> FETCH_HEAD Updating 67b6537..ee38b20 error: The following untracked working tree files would be overwritten by merge: .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs

.metadata/version.ini Please move or remove them before you can merge. Aborting

git did not exit cleanly (exit code 1) (1094 ms @ 16/07/2014 3:32:47 PM)

Can you give me some feedback on this. Do I need to force an update or synch?

gturri
  • 13,807
  • 9
  • 40
  • 57
Richie
  • 4,989
  • 24
  • 90
  • 177
  • `HEAD` **is not actually a branch in your remote repo**, it's a symbolic reference that points to the default branch in the remote, which is usually `master`. –  Jul 16 '14 at 04:17
  • possible duplicate of [Difference between 'git pull' and 'git fetch'?](http://stackoverflow.com/questions/292357/difference-between-git-pull-and-git-fetch) –  Jul 16 '14 at 04:23
  • @Cupcake ah.. thanks for pointing that out. It will help me with my terminology in the future. – Richie Jul 16 '14 at 04:24
  • @Cupcake I've read that link. So are you saying that if I did a pull instead of a fetch the remote commits would be pulled down to my local. Why would a fetch not work? – Richie Jul 16 '14 at 04:26
  • [The answer to your question](http://stackoverflow.com/a/292359/456814) is simple: "*In the simplest terms, 'git pull' does a 'git fetch' followed by a 'git merge'.*". –  Jul 16 '14 at 04:31
  • Did you try looking up how to merge or pull using TortoiseGit? –  Jul 16 '14 at 05:24
  • Actually sorry. I forgot to add something about the TortoiseGit pull to my answer. Let me add it. – Richie Jul 16 '14 at 05:29
  • Also, you know you can copy and paste from your terminal, right? You might have to modify the preferences, but you can select to highlight and right-click to copy. It's easier to read than screenshots. –  Jul 16 '14 at 05:34
  • The error you get when trying the pull: "*The following untracked working tree files would be overwritten by merge:*" It means you have a dirty working copy with modified or untracked files. You either need to stash them or commit them before you do the pull/merge. In general, you never want to pull or merge into a dirty working copy. –  Jul 16 '14 at 05:42
  • ok. So I got rid of the untracked files and it worked. The enhancements branch is no up to date! Thanks – Richie Jul 16 '14 at 05:43

1 Answers1

2

It looks like the problem that you're having is that you're only fetching your enhancements branch into your local repo, but you're not actually merging the remote-tracking branch origin/1.0.0-Enhancements into your local 1.0.0-Enhancements branch.

Basically, you're branches are set up like this (let X represent your enhancements branch):

Branches

As you see in the diagram above, there are 3 branches involved:

  1. The local version of X.
  2. The remote version of X.
  3. A local remote-tracking branch origin/X, which keeps track of where the remote version of X is.

By using git fetch, you update the local remote-tracking branch origin/1.0.0-Enhancements in your local repo...but that's a separate branch from your local 1.0.0-Enhancements branch.

So, what you want to do is either:

  1. git pull, or
  2. git merge the remote-tracking branch.

Note that git pull is really just a combination of git fetch followed by git merge of the branch that you just fetched.

Option 1: Merge

Since you've already fetched, you just need to merge origin/1.0.0-Enhancements into your local 1.0.0-Enhancements branch. I don't know how you do this in TortoiseGit (I stopped using that years ago), but if you want to do it from the command line, you simply do

git checkout 1.0.0-Enhancements
git merge origin/1.0.0-Enhancements

Option 2: Pull

In the future, in cases where you didn't fetch first, you can execute a pull into your local branch from the remote branch instead. Again, I don't know how to do this in TortoiseGit anymore, but if you wanted to do it from the command line, you simply do

git checkout 1.0.0-Enhancements
git pull origin 1.0.0-Enhancements

Note on the HEAD symbolic reference

So the symbolic reference origin/HEAD is not a branch. It's simply a special reference that points to the default branch in the (bare) remote repo...the same branch that gets checked out by default by any clones of that repo.

In a non-bare repo, HEAD is still a symbolic reference, but instead of pointing to a default branch, it instead points to either the currently checked out branch, or the currently checked out commit, if you're not currently on the tip of a branch (e.g. "detached HEAD" state).

Documentation

  • Thanks for your explanation. I did not know local remote-tracking branch. I tried both of your suggestions and they did not work. I've updated my post to show the output – Richie Jul 16 '14 at 05:09
  • sorry i just sent them through now – Richie Jul 16 '14 at 05:18
  • Thank you. Even though we took a few goes to get this right your explanation in particular of the remote tracking branch was very interesting and knowledge I didn't have. Appreciate your time on this. – Richie Jul 16 '14 at 05:44
  • You're welcome `;)`. If you have time to read it, I also recommend that you check out the FREE [Pro Git book](http://git-scm.com/book), which is available online and also in Kindle, iPad, and PDF versions, especially chapters 1-3, 6-6.5. It's how I went from Git n00b to [Git Master](http://stackoverflow.com/users/456814/cupcake)! `:D` –  Jul 16 '14 at 05:46