Cloning a repository without making it the origin remote

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)?

  • git push fails: `refusing to update checked out branch: refs/heads/master`
  • git merge: filter files to avoid silly conflicts (like whitespace or case changes)
  • git remote merge commit causing false dependencies in gerrit
  • Git2go: Simulate git checkout and an immediate git push
  • Git : Determine if branch is in a merge conflict state
  • aws beanstalk 403 error while deploying
  • Edit: The repository has only one branch, and no tags.

  • Update git submodules shallowly with the '--depth' option
  • How can I ignore all files except those with a certain extension in git?
  • Git - Checkout a remote tag when two remotes have the same tag name
  • For the Jenkins git plugin, where is it recommended to run `git config`?
  • Using github to host public git repositories whilst ensuring that sensitive data files remain untracked
  • Could not read from remote repository when pushing to Heroku (Rails Tutorial 5)
  • 5 Solutions collect form web for “Cloning a repository without making it the origin remote”

    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).

    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.

    The general way to handle such a trasfer would be git bundle. See Backup of github repo.

    From your second (new) desktop:

    git bundle create file:///\\oldDesktop/share/myGitRepo --all

    to create one local file from which you will be able to clone a local git repo.

    Note: the file:/// protocol will support UNC (Universal Naming Convention) Windows path, with the rest of the path using ‘/‘ instead of ‘\‘. See Git on a Windows Lan.

    I do believe you would need to delete the remote branch.

    Does the remote repo have more branches than just master? It’s trickier if it does; you need to make local copies of all of the branches as well because when you delete the remote, all the remote/origin branches will go away. (I just tried it!)

    So, you can do something like this:

    git clone <remote_url>
    cd <repo>
    for b in $(git branch -r | grep -v HEAD | grep -v master);do
        git branch $(basename $b) $b
    git remote rm origin

    Of course, as Jess Bowers said, it’s even easier to just tar or zip it up and move the files, if you have access to the machine to do that.

    You can also just make a bare clone:

    git clone --bare <remote_url>

    and then make new clones from that.

    Git Baby is a git and github fan, let's start git clone.