Frage

There are a dozen similar questions, with everyone posting long answers trying to talk the asker out of it.

Is it possible to create a branch in such a situation?

I do not want to clone the repo, just so that I can create a branch in that copy's working directory, push it, and then delete the whole thing again. The script that will create this branch (after checking to see if it exists) already has access to the bare repo in Gitolite and can issue the commands directly. "git checkout" complains that the operation must be performed in a work tree.

War es hilfreich?

Lösung

You can just go a little lower-level, in a bare repo.

git branch is willing to create a new branch in a bare repo. Just give it a commit to start from and you've made a new branch name pointing at an existing commit:

cd foo.git
git branch newbranch b6636ec88ba0750aec2706865653eb55031fb892

You can also use git update-ref, which is even lower-level than git branch and can create references outside of the refs/heads/ namespace:

git update-ref refs/special/ziggy b6636ec88ba0750aec2706865653eb55031fb892
git update-ref -d refs/special/delete

Edit: And, you can make indirect refs with git symbolic-ref, e.g.:

git symbolic-ref MAGIC refs/tags/v1.3

(normally this would only be used to make HEAD be a different indirect ref; the main point here is that this command, like git update-ref, requires that you spell out the whole name-space name).

Andere Tipps

Let's take a different angle than talking you out of it, then.

You can do anything you want to a bare repo.

  • either the hard way by just manipulating the files there the way you want
  • or by setting GIT_DIR and using pure-repo commands
  • possibly additionally setting GIT_INDEX_FILE if you need a local index
  • possible additionally setting GIT_WORK_TREE if you need one of those

Some documentation about the relevant environment variables.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top