git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Dangers of working on a tracking branch

From
Nicolas Pitre <nico@cam.org>
Date
Feb 16, 2007, 16:34 UTC
Message-ID
<alpine.LRH.0.82.0702161044100.18370@xanadu.home>
In-Reply-To
<17877.51730.418633.750922@lisa.zopyra.com>
On Fri, 16 Feb 2007, Bill Lear wrote:
Show 5 quoted lines
> Ok, I'm trying to come up with an experiment that verifies this, so
> I can give a concrete example to our developers.
> 
> I don't seem to be able to get it to fail, but I sure remember having
> severe problems with this in practice.
Try this:
	# create first repository
	mkdir foo
	cd foo
	git init-db
	echo FOO > biz
	git add biz
	git commit -a -m "commit 1 in foo"
	# clone this repository elsewhere
	cd ..
	git clone foo bar
	cd bar
	# modify the tracking branch (origin in this case)
	git checkout origin
	echo BAR > biz
	git commit -a -m "modify tracking branch in bar"
	# go back to original repo and modify it
	cd ../foo
	echo BAZ > biz
	git commit -a -m "modify master branch in foo"
	# now back to the cloned repo
	cd ../bar
	git fetch	# it fails
	git push	# itfails
	git pull	# it almost performs the merge but...

Because you now have a conflict to resolve, you might wish to inspect what the remote state actually is. But because you modified your origin branch you don't have any pristine version of what the remote has, except maybe the MERGE_HEAD. But if you work in a complex project, MERGE_HEAD will not stay there for long if you move around.

Imagine that you want to move to another branch, say master, because right now you don't feel like resolving this ultra complex merge:

	git checkout master	# it fails (unresolved merge)
	git checkout -f		# succeeds, discarding the merge

But at this point you still don't have any way to look at the remote's content. If instead the origin branch was untouched and the work had occurred in the master branch, then you could git-log the origin branch, you could git-diff your master branch with the origin branch, you could even checkout the origin content to test it, etc. But since you added commits on top of the origin branch then you cannot do any of that because it is impossible to update the origin branch with the remote stuff. Well you can force it of course:

	git fetch -f
But by doing so you lose all the work you committed on top of origin.

BTW I checked out v1.4.4.1 to verify the above operations..... and this GIT version really feels odd compared to v1.5.0

Nicolas
Previous: Santi BéjarNext: Bill Lear
Message 20 of 22 in “Dangers of working on a tracking branch”
  1. Bill LearFeb 15, 2007
  2. Nicolas PitreFeb 15, 2007
  3. Bill LearFeb 15, 2007
  4. Bill LearFeb 15, 2007
  5. Jeff KingFeb 15, 2007
  6. Bill LearFeb 15, 2007
  7. Jeff KingFeb 15, 2007
  8. Bill LearFeb 15, 2007
  9. Shawn O. PearceFeb 15, 2007
  10. Bill LearFeb 15, 2007
  11. Shawn O. PearceFeb 15, 2007
  12. Jeff KingFeb 15, 2007
  13. Bill LearFeb 15, 2007
  14. Jakub NarebskiFeb 16, 2007
  15. Bill LearFeb 16, 2007
  16. Jeff KingFeb 16, 2007
  17. Bill LearFeb 16, 2007
  18. Jeff KingFeb 16, 2007
  19. Santi BéjarFeb 16, 2007
  20. Nicolas PitreFeb 16, 2007
  21. Bill LearFeb 16, 2007
  22. Nicolas PitreFeb 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.