Kenster
Kenster

Reputation: 25380

Stop git from bringing changes to master into my branch?

I'll preface this by saying I'm relatively new to git, and I'm leaning on the Eclipse git GUI probably more than I should. Anyway, here's what happened:

  1. I created a remote branch from origin/master and checked out that branch.
  2. Another developer checked in a change to master. The change doesn't compile on my system, for complicated reasons.
  3. I did a git pull this morning, while checked out on my branch, and the changes to master were brought into my workspace.

So now the non-working versions of certain files are in my workspace, even though I branched before those changes were checked in. This is a bit of a surprise.

Could someone help me understand why git is importing these changes while I'm branched, and how to control this behavior? At the least, I'd like to revert the files that don't compile to earlier versions, and prevent git from merging additional changes from master into my branch until I'm ready to merge back into master. Ideally, I'd like to bring in some of the changes made by the other developer, because some files in the project are very difficult to merge.

Here is the git config for my copy of the repository. I'm on MYBRANCH:

[core]
    symlinks = false
    repositoryformatversion = 0
    filemode = false
    logallrefupdates = true
[remote "origin"]
    url = ssh://[email protected]:7999/foo/bar.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "SOMEOTHERBRANCH"]
    remote = origin
    merge = refs/heads/master
[branch "MYBRANCH"]
    remote = origin
    merge = refs/heads/master

Upvotes: 0

Views: 58

Answers (2)

Oscar
Oscar

Reputation: 61

Additionally to revert changes from your branch you should see the command git reset http://git-scm.com/docs/git-reset

Upvotes: 1

David Deutsch
David Deutsch

Reputation: 19015

So the problem here is that MYBRANCH is set up to track origin/master, which means that when you do a git pull, origin/master will be merged into it. You can untrack it by doing git config --unset branch.MYBRANCH.merge. Assuming there is an origin/MYBRANCH, you can track it by doing git branch -u origin/MYBRANCH (while on MYBRANCH). If origin/MYBRANCH does not yet exist, you can create/track it with git push -u origin MYBRANCH.

Upvotes: 3

Related Questions