Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a repository without making it the origin remote

Tags:

git

git-clone

I'm cloning a git repository from a computer that's going to be wiped.

Is it possible to clone a repository without making the original repository origin/master? Or do I need to clone it, and then delete the remote branch (which is done with git remote rm origin)?

Edit: The repository has only one branch, and no tags.

like image 933
Andrew Grimm Avatar asked Feb 12 '10 01:02

Andrew Grimm


People also ask

How do I override git remote origin?

Change Git Remote URL For example, let's say that you want to change the URL of your Git origin remote. In order to achieve that, you would use the “set-url” command on the “origin” remote and you would specify the new URL. Congratulations, you successfully changed the URL of your Git remote!

Does git clone affect original?

When you clone a repository, any changes you push to GitHub will affect the original repository. To make changes without affecting the original project, you can create a separate copy by forking the repository.


2 Answers

It is not necessary to make the original repository the "origin" remote to clone the master branch.

On the new machine, create a new repository:

git init foo 

Then pull the old repository into the new one, without creating a remote:

cd foo git pull <reference to old repository> 

However, it should be noted that the easiest way to save off a repository would be to just zip the repository's directory up and move the files to a new machine. That will preserve any and all remotes, tags, etc.

As noted below, when copying the repository, be careful when going from case-sensitive file systems (eg. Linux, Mac, NTFS) to non-case sensitive (eg. Fat32).

like image 95
Jess Bowers Avatar answered Sep 23 '22 06:09

Jess Bowers


First, you can use --origin <name> option of git clone

--origin <name>, -o <name>

Instead of using the remote name origin to keep track of the upstream repository, use <name>.

Second, you can use git remote add to add repository to fetch from to existing repository (so you can use git init, then git remote add <name> <url>).


If you want to create a mirror of repository, with refs/heads/* going into refs/heads/* in clone, you can init repository, setup appropriate refspec, and then fetch...

Or you can use git clone --mirror, which should answer current version of OP question.

This would however not preserve configuration (including remotes), worktree state, reflogs, etc. For this you would need to copy repository whole, as Jess Bowers said.

like image 32
Jakub Narębski Avatar answered Sep 19 '22 06:09

Jakub Narębski