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

Re: [PATCH 10/10] push: teach push to be quiet if local ref is strict subset of remote ref

From
Steffen Prohaska <prohaska@zib.de>
Date
Nov 2, 2007, 11:40 UTC
Message-ID
<DEFB6632-9D04-4CDB-8FF0-DE2214826A5B@zib.de>
In-Reply-To
<7v7il13p1g.fsf@gitster.siamese.dyndns.org>
On Nov 2, 2007, at 11:44 AM, Junio C Hamano wrote:
Show 9 quoted lines
> Steffen Prohaska <prohaska@zib.de> writes:
>
>> - in a workflow that is base on shared branches (CVS-style),
>>   ...
>>   In addition push should push back to the remote branch a local
>>   topic was originally branched off.
>
> Why?  If it is shared, and if you are shooting for the simplest
> set of commands, wouldn't you work this way?
Yes. I would work exactly this way with current git.
> 	$ git clone $public my-work-dir
>         $ cd my-work-dir
>         $ git checkout -b --track foo origin/foo

So the implicit rule here is "name a branch identical in all repositories you're dealing with" right?

That is foo is named foo at the remote, named foo as a tracking branch (git handles this automatically) and is named foo as your local branch.

I believe it is reasonable. Though I have two questions:
1) If this is best practice, why doesn't save git me from typos?
    Why do I need to type "foo" correctly twice?
2) What shall I do if I am dealing with more than one shared
    repository?  Andreas' group should already run into problems
    here. They have several shared repos and if they want to
    checkout several local branches from different repos they
    need to somehow encode the name of the remote in the name
    of the local branch.
Show 5 quoted lines
>         $ hack hack hack, commit, commit, commit *on* *foo*
>         $ git push $public foo
>
> I think the recent git defaults to --track anyway so the third
> step do not spell out --track.
It does.
> With your "remote.$public.push = HEAD", the last step would be
> "git push" without any parameter.

Indeed. Or with my "branch.$name.push" it would just be "git push" as well. And I'd be probably happy then.

Show 5 quoted lines
> If you do use private topics, then the story would change this
> way:
>
>         $ git checkout -b --track foo origin/foo
>         $ git checkout -b topic1 foo ;# or origin/foo

I'd be more happy without 'or'. I really want to give a single recommendation.

So the question here is: Should I branch off the local branch or should I branch off the remote branch? When should I do what? What is best practice and what is used for 'exceptional' situations?

Show 9 quoted lines
>         $ hack hack hack, commit, commit, commit on topic1
>         $ git checkout -b topic2 foo ;# or origin/foo
>         $ hack hack hack, commit, commit, commit on topic2
>         $ git checkout foo
>         $ git merge topic1
>         $ test test test; # test _your_ changes
>         $ git merge topic2
>         $ test test test; # test _your_ changes
>         $ git push ;# again push 'foo' out
This focuses testing on the integration of topic1 with topic2.
You could as well do the following
	$ git checkout -b topic1 origin/foo
	$ hack ...
	$ git checkout -b topic2 origin/foo
	$ hack ..
	[ later ]
	$ git checkout topic1
	$ git pull # or git fetch; git rebase origin/foo
	$ test test test
	$ git push origin topic1:origin/foo
	[ later ]
	$ git checkout topic2
	$ git pull # or git fetch; git rebase origin/foo
	$ test test test
	$ git push origin topic2:origin/foo
With my "branch.$name.push" it would just be "git push" here.

This workflow focuses testing on the integration of each of your topics with the new changes on the shared branch independently of your other topic.

You're done at this point. No need to merge a second time, no need to reset branches.

It's probably a good idea to delete your local branches now. And there is one minor question related to that: Where to park your HEAD if you want to clean up _all_ of your local branches because you have nothing left to do? Everything is on the shared remote branch. The only thing you're interested now is to checkout new changes from the shared branch if interesting work was done by others.

> This may fail to fast forward.  You may at this time want to
> "git fetch" first, rebase topic1 or topic2 that conflict with
> the other side on top of updated origin/foo, rebuild foo and
> push the result out, like this:
Or you could just pull
[ this continues Junio's example from above, you are on branch foo. ]
	$ git pull
	$ test test; # test of your integration of topic1, topic2
	             # with the new changes on the shared branch
	$ git push
> 	$ git fetch
>         $ git rebase origin/foo topic1
>         $ git branch -f foo origin/foo
Here is another interesting point.

Would you recommend "git branch -f foo origin/foo" over "git checkout foo; git reset --hard origin/foo"? I think the first command is safer because it doesn't throw away uncommitted changes. However it fails if you are already on branch foo. Then it says "fatal: Cannot force update the current branch.". It is not very intuitive if I'd ask users to first leave the branch they want to modify, only to be able to use "git branch". "git reset" always lets you achieve your goal. (BTW, I don't recommend having local changes while doing integration testing ... but who knows maybe someone feels comfortable with it.)

Show 5 quoted lines
>         $ git checkout foo
>         $ git merge topic1
>         $ git merge topic2
>         $ test test test
>         $ git push

Using rebase requires more commands than using pull, and more intrusive commands like "branch -f" or "reset --hard" are involved.

That doesn't mean that you should not use rebase. But it certainly needs more explanation.

Another related question is the following: After some time the user decides that some help on topic1 would be appreciated and another developer promises to help. So they agree to work on a shared branch name topic1. The first developer starts with

	$ git push origin topic1
 From now on he _MUST NOT_ use rebase any longer! So starting
to work on the topic with a second developer completely changed
the best practice. From now no rebase is forbidden, which was
best practice before.

So the question for me is: do I want to teach developer a pull or a rebase workflow first? Currently I believe pull will be safer for them, better supported by git, and there will be situations they must use pull. If the only nuisance are loops in the history when viewing them in gitk, I'm happy to accept this.

Show 5 quoted lines
>>   ... This makes the need for
>>   pushing to a branch named differently on the remote side more
>>   likely than in a pull-oriented workflow,
>
> So I do not understand this remark.

Yeah, I should have added some explanation here. I had Andreas' 200-local-branches and the topic1/topic2 example in mind that does the integration against the shared branch.

	Steffen
Previous: Junio C HamanoNext: Andreas Ericsson
Message 32 of 53 in “improve refspec handling in push”
  1. 0/10 improve refspec handling in pushSteffen Prohaska, Oct 28, 2007
  2. 01/10 push: change push to fail if short refname does not existSteffen Prohaska, Oct 28, 2007
  3. 02/10 push: teach push new flag --createSteffen Prohaska, Oct 28, 2007
  4. 03/10 push: support pushing HEAD to real branch nameSteffen Prohaska, Oct 28, 2007
  5. 04/10 push: add "git push HEAD" shorthand for 'push current branch to default repo'Steffen Prohaska, Oct 28, 2007
  6. 05/10 rename ref_matches_abbrev() to ref_abbrev_matches_full_with_fetch_rules()Steffen Prohaska, Oct 28, 2007
  7. 06/10 add ref_abbrev_matches_full_with_rev_parse_rules() comparing abbrev with full ref nameSteffen Prohaska, Oct 28, 2007
  8. 07/10 push: use same rules as git-rev-parse to resolve refspecsSteffen Prohaska, Oct 28, 2007
  9. 08/10 push: teach push to accept --verbose optionSteffen Prohaska, Oct 28, 2007
  10. 09/10 push: teach push to pass --verbose option to transport layerSteffen Prohaska, Oct 28, 2007
  11. 10/10 push: teach push to be quiet if local ref is strict subset of remote refSteffen Prohaska, Oct 28, 2007
  12. Junio C HamanoOct 30, 2007
  13. Steffen ProhaskaOct 30, 2007
  14. Andreas EricssonOct 30, 2007
  15. Steffen ProhaskaOct 30, 2007
  16. Junio C HamanoOct 30, 2007
  17. Steffen ProhaskaOct 31, 2007
  18. Junio C HamanoOct 31, 2007
  19. Junio C HamanoOct 31, 2007
  20. Steffen ProhaskaOct 31, 2007
  21. Junio C HamanoOct 31, 2007
  22. Steffen ProhaskaOct 31, 2007
  23. Junio C HamanoOct 31, 2007
  24. Steffen ProhaskaNov 1, 2007
  25. Andreas EricssonNov 1, 2007
  26. Steffen ProhaskaNov 1, 2007
  27. Junio C HamanoNov 1, 2007
  28. Steffen ProhaskaNov 2, 2007
  29. Junio C HamanoNov 2, 2007
  30. Steffen ProhaskaNov 2, 2007
  31. Junio C HamanoNov 2, 2007
  32. Steffen ProhaskaNov 2, 2007
  33. Andreas EricssonNov 2, 2007
  34. Tom PrinceNov 2, 2007
  35. Andreas EricssonNov 2, 2007
  36. Steffen ProhaskaNov 2, 2007
  37. Junio C HamanoNov 2, 2007
  38. Junio C HamanoNov 2, 2007
  39. Andreas EricssonNov 1, 2007
  40. Steffen ProhaskaNov 1, 2007
  41. Andreas EricssonNov 1, 2007
  42. Wincent ColaiutaNov 2, 2007
  43. Johannes SchindelinNov 2, 2007
  44. Steffen ProhaskaNov 2, 2007
  45. Wincent ColaiutaNov 2, 2007
  46. Daniel BarkalowOct 30, 2007
  47. Junio C HamanoOct 30, 2007
  48. Steffen ProhaskaOct 30, 2007
  49. Junio C HamanoOct 30, 2007
  50. Junio C HamanoOct 30, 2007
  51. Junio C HamanoOct 30, 2007
  52. Steffen ProhaskaOct 30, 2007
  53. Junio C HamanoOct 30, 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.