All of lore.kernel.org
 help / color / mirror / Atom feed
* Why can't git open empty branches ?
@ 2012-04-11 10:35 Hadmut Danisch
  2012-04-11 10:59 ` Jonathan Nieder
  0 siblings, 1 reply; 8+ messages in thread
From: Hadmut Danisch @ 2012-04-11 10:35 UTC (permalink / raw)
  To: git

Hi,

when creating a new branch in git, it is by default filled with the
contents of the current branch.

Sometimes a new but empty branch is needed. There are plenty of
instructions in the web to achieve this with „dirty tricks”, i.e. fiddle
around with git's internals. Which is poor design.



Why doesn't git's branch command support opening empty branches in a
clean an natural way?



regards
Hadmut

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 10:35 Why can't git open empty branches ? Hadmut Danisch
@ 2012-04-11 10:59 ` Jonathan Nieder
  2012-04-11 11:06   ` Hadmut Danisch
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Nieder @ 2012-04-11 10:59 UTC (permalink / raw)
  To: Hadmut Danisch; +Cc: git

Hadmut Danisch wrote:

> when creating a new branch in git, it is by default filled with the
> contents of the current branch.
>
> Sometimes a new but empty branch is needed. There are plenty of
> instructions in the web to achieve this with „dirty tricks”, i.e. fiddle
> around with git's internals.

	git init ../unrelated-topic
	cd ../unrelated-topic
	hack away...
	git commit
	cd -
	git fetch ../unrelated-topic master:<new branch>

Or:

	git checkout --orphan <new branch>
	git rm -fr .
	hack away...

Please feel free to contact the authors of the instructions you found
on the web to fix them.

Thanks and hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 10:59 ` Jonathan Nieder
@ 2012-04-11 11:06   ` Hadmut Danisch
  2012-04-11 11:21     ` Matthieu Moy
  0 siblings, 1 reply; 8+ messages in thread
From: Hadmut Danisch @ 2012-04-11 11:06 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git

Am 11.04.2012 12:59, schrieb Jonathan Nieder:
> 	git checkout --orphan <new branch>
> 	git rm -fr .



I would have expected something more obvious and intuitive like

  git branch --empty



It is not really plausible to create a new branch by checking out a
non-existing one.

However, this helps. Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 11:06   ` Hadmut Danisch
@ 2012-04-11 11:21     ` Matthieu Moy
  2012-04-11 11:47       ` Hadmut Danisch
  0 siblings, 1 reply; 8+ messages in thread
From: Matthieu Moy @ 2012-04-11 11:21 UTC (permalink / raw)
  To: Hadmut Danisch; +Cc: Jonathan Nieder, git

Hadmut Danisch <hadmut@danisch.de> writes:

> It is not really plausible to create a new branch by checking out a
> non-existing one.

... but it is hardly useful to create a new branch unless you want to
check it out.

I think the most common way to create a branch with Git is "git checkout
-b new-branch", which does the creation+checkout in a single command.
"git checkout --orphan" is the natural extension of it.

BTW, it is rarely good practice to create an empty branch in an existing
repository. You'll have different branches that do not share any
history, and they would likely be better in separate repositories (or at
least, be in separate local repositories, pushed to the same remote bare
repository, in which case you don't need anything special, just "git
init" and "git push"). That doesn't mean you shouldn't do it, but just
that you may want to think twice before doing it ;-).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 11:21     ` Matthieu Moy
@ 2012-04-11 11:47       ` Hadmut Danisch
  2012-04-11 12:19         ` Jonathan Nieder
                           ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hadmut Danisch @ 2012-04-11 11:47 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Jonathan Nieder, git

Am 11.04.2012 13:21, schrieb Matthieu Moy:
> BTW, it is rarely good practice to create an empty branch in an existing
> repository. You'll have different branches that do not share any
> history, and they would likely be better in separate repositories (or at
> least, be in separate local repositories, pushed to the same remote bare
> repository, in which case you don't need anything special, just "git
> init" and "git push"). That doesn't mean you shouldn't do it, but just
> that you may want to think twice before doing it ;-).

That's a pretty good point for discussion.


Sometimes people are working on different sorts of information, that are
nevertheless closely related, e.g. open source software and the web
pages describing it (like in git hub), or a web server tree and the
software generating it. They are related, but do not logically share a
history.


Creating independent branches by pushing two separates into a single
remote bare is a nice idea, but if I understood git correctly, the very
first commit in a repos is always to the master branch, where you have
two masters trying to push into the shared remote bare. This is
obviously solvable if you use the correct commands and maybe delete and
re-clone the repos, but this is all overcomplicated and non-trivial.
Nothing I could do without reading manuals.

So your proposal might work perfectly, but in my eyes it is error prone
and not user friendly.

regards

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 11:47       ` Hadmut Danisch
@ 2012-04-11 12:19         ` Jonathan Nieder
  2012-04-11 12:19         ` Matthieu Moy
  2012-04-11 14:16         ` Holger Hellmuth
  2 siblings, 0 replies; 8+ messages in thread
From: Jonathan Nieder @ 2012-04-11 12:19 UTC (permalink / raw)
  To: Hadmut Danisch; +Cc: Matthieu Moy, git

Hadmut Danisch wrote:

> Creating independent branches by pushing two separates into a single
> remote bare is a nice idea, but if I understood git correctly, the very
> first commit in a repos is always to the master branch, where you have
> two masters trying to push into the shared remote bare. This is
> obviously solvable if you use the correct commands and maybe delete and
> re-clone the repos, but this is all overcomplicated and non-trivial.
> Nothing I could do without reading manuals.

I suppose you had to read the manual to learn the "git commit" and
"git branch -m" commands, yes.  But what's wrong with that, or how
could we fix it?

	git init code
	cd code
	... hack away ...
	git remote add origin <url>
	git push -u origin master
	cd ..

	git init website
	cd website
	... hack away ...
	git branch -m website
	git remote add origin <url>
	git push -u origin website
	cd ..

I wonder if there is a potential documentation or error message update
lurking behind these questions.

Hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 11:47       ` Hadmut Danisch
  2012-04-11 12:19         ` Jonathan Nieder
@ 2012-04-11 12:19         ` Matthieu Moy
  2012-04-11 14:16         ` Holger Hellmuth
  2 siblings, 0 replies; 8+ messages in thread
From: Matthieu Moy @ 2012-04-11 12:19 UTC (permalink / raw)
  To: Hadmut Danisch; +Cc: Jonathan Nieder, git

Hadmut Danisch <hadmut@danisch.de> writes:

> e.g. open source software and the web pages describing it (like in git
> hub), or a web server tree and the software generating it. They are
> related, but do not logically share a history.

In these cases, you'll want to have two working directories, if only to
avoid:

git checkout documentation
# fix a typo
git commit
git checkout code
make
# complete rebuild triggered.

> Creating independent branches by pushing two separates into a single
> remote bare is a nice idea, but if I understood git correctly, the very
> first commit in a repos is always to the master branch,

Not necessarily. I don't see an option in "git init" to change the
default branch name, but you can

git init foo
cd foo
git checkout -b whatever-branch-name

and work.

Otherwise, you can have a branch that is locally called "master", and
push it as another name (but that is probably the "error prone" in your
message ;-) ).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why can't git open empty branches ?
  2012-04-11 11:47       ` Hadmut Danisch
  2012-04-11 12:19         ` Jonathan Nieder
  2012-04-11 12:19         ` Matthieu Moy
@ 2012-04-11 14:16         ` Holger Hellmuth
  2 siblings, 0 replies; 8+ messages in thread
From: Holger Hellmuth @ 2012-04-11 14:16 UTC (permalink / raw)
  To: Hadmut Danisch; +Cc: Matthieu Moy, Jonathan Nieder, git

Hi Hadmut ;-)

On 11.04.2012 13:47, Hadmut Danisch wrote:
> Creating independent branches by pushing two separates into a single
> remote bare is a nice idea, but if I understood git correctly, the very
> first commit in a repos is always to the master branch, where you have

AFAIK the only thing that makes master the initial branch is the file 
.git/HEAD that points to master after you "git init". This is not hardcoded.

 > So your proposal might work perfectly, but in my eyes it is error
 > prone and not user friendly.

Serious errors should not happen since the bare repo on the server is 
created with the flag denyNonFastForwards. So even if you had a master 
branch in both repos, only one of them, the first one, would succeed in 
pushing to the server, a push of the second one would give you an error 
message. Maybe not user friendly, but safe.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-04-11 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11 10:35 Why can't git open empty branches ? Hadmut Danisch
2012-04-11 10:59 ` Jonathan Nieder
2012-04-11 11:06   ` Hadmut Danisch
2012-04-11 11:21     ` Matthieu Moy
2012-04-11 11:47       ` Hadmut Danisch
2012-04-11 12:19         ` Jonathan Nieder
2012-04-11 12:19         ` Matthieu Moy
2012-04-11 14:16         ` Holger Hellmuth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.