simpleuser
simpleuser

Reputation: 1682

does git have functionality lke cvs's rtag

In CVS, we could programatically create a new branch of existing source using the "rtag" command, which did not require a copy of the repository.

Does git support functionality of this kind, making a branch of existing files in a remote git repository without having a local copy of it? Or does the distributed nature of git preclude this?

(I'm trying to save the 20+ minutes it would take to make a freestanding copy of the repository, just to run a 'git branch' command.)

Edit for additional information:

If we have a cvs repository with a branch "ReleaseCandidate", and a script called "makearelease.sh", the script can run a command like "cvs rtag -r ReleaseCandidate -b Release1p0" in a random, empty directory and make a new branch named 'Release1p0' containing all the files in 'ReleaseCandidate' branch and it does not need any local copies of the files from the repository or from the CVS branch 'ReleaseCandidate'.

Upvotes: 3

Views: 151

Answers (2)

masonk
masonk

Reputation: 9788

I'm not sure what you're asking. If you're asking can you create a new branch of the repo without copying files, the answer is yes. git checkout -b. This copies no files at all.

If you're asking if it's possible to create a partial version of a remote repository, the answer is no. Every git repo is an entire clone of the repo. There is no concept of a partial repository. This is required by the way git internally. (In order to build the SHA-1 hash of a tree, it must hash all of the files in the tree. If you tried to create a partial copy of a tree, then its SHA-1 hash would be different from the head of the branch that you're trying to partially clone. In effect, they would simply be different commits that point to the same ancestor.)

If you're asking can you just make your local working directory look like the working directory of a remote non-bare repo without downloading all of git's history, the answer is yes (edit: with "shallow clones", thanks for the correction), but it doesn't help you interact with the remote in the way you seem to want.

Upvotes: 0

torek
torek

Reputation: 489073

In git, all repositories are local, always. You can have a remote interface to a local repository (e.g., that's what github's API gives you: the repo is local to github, and the API is an interface), but the repo itself is local. So there's no such thing as a "remote repo", in the sense you mean here, just a "remote interface".

That said, it's possible to use the built in remote interfaces (e.g., the push protocol git uses over ssh) to create a new branch or lightweight tag, without actually having a local clone, as the push protocol starts out by receiving the remote's refs (a la git ls-remote), and then the system doing the push can send object-packs, ref updates, or both. You could send a refs/heads/foo or refs/tags/foo reference with a known (from the received refs) head SHA1 and call it good ... but that would be rather error prone since you could lose a race with someone else adding new commits, and branch from, or tag, the wrong commit. Thus there's nothing built in to git to do this.

So, you could write one, but it would probably take more than 20 minutes. :-)

Upvotes: 5

Related Questions