Question

The admin has told me not to merge develop into my branches before pushing them to remote, and that I should create new branches based on master, that way no code from develop will accidentally get merged into master. OK, that has worked fine for several weeks, but a couple of days ago I accidentally merged develop into one of my branches. That didn't create a big problem for the admin, he just told me not to do it again, but since then I started using "git branch --contains" to make sure.

Problem: When I fetch the remote master and run "git branch --contains", it shows that develop is part of it:

git branch --contains
  develop
* master

How can that be possible??

I see 3 possible explanations:

  1. remote master was at some point accidentally merged with develop
  2. some unknown error
  3. I'm not updating my local branch correctly with the fetched master

  1. is very unlikely since the admin is a guru who couldn't possibly have let that happen
  2. is what I suspect is happening
  3. possible, but I think I've been doing it correctly all these weeks with this code:

git fetch
git checkout master
git reset --hard origin/master
git clean -f
git pull origin master

So as long as develop is in master I cannot create/push any new branches.

Any idea what's going on?

Was it helpful?

Solution 2

The problem was my understanding of git branch --contains. It doesn't list branches contained in the currently checked out branch, but branches which contain it.

So to know if master contains develop I should do

git checkout develop
git branch --contains
* develop

So there was no problem after all. As this shows, master is not part of the list of branches which contain develop.

While this showed that develop did contain master, but that's ok.

git checkout master
git branch --contains
  develop
* master

OTHER TIPS

It's possible that your local develop branch hasn't been updated since the last time that a commit made it all the way into master. Make sure that your local develop branch is up to date:

git checkout develop
git fetch
git merge --ff-only origin/develop

A good way to figure out what's going on with your branch topology is to run this command:

git log --oneline --decorate --graph --all

Or this one, if you're more of a GUI person:

gitk --all

You'll see a graph showing all of your commits, with colored markers labeling the position of each local and remote-tracking branch. It's a good way to keep track of what's where, when you have lots of branches and complicated workflows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top