Search code examples
gitgit-clone

Git clone a clone but only update remote from 1st clone


I have this situation where I have 2 home computers but only 1 is allowed access to a remote machine which hosts the remote repository and for various reasons I can't do my work on this machine.

What I want to do is this: remote repo -> clone 1 -> clone 2 (do my work), then clone 2 -> clone 1 -> remote repo.

I want to work on clone 2, push to clone 1 then push clone 1 back to the remote repository.

I can do the clone of the clone, but when I try to push back to clone 1, I get an error stating that the master is checkedout and I cannot push to it.

What is the cleanest way to do what I am trying achieve, I am relatively new to git (my current solution is just to copy clone 1, do my changes then copy it back and update - but this causes all sorts of issues).

I have been using sourcetree & tortoisegit, but don't mind some command line work

Cheers

ice


Solution

  • When you create Clone 1, use git clone --bare to create a bare repository. As you don't modify and commit files in Clone 1, it's not necessary to checkout a branch in Clone 1. A bare repository is enough to work as a transfer station.

    If you do need a non-bare repository for Clone 1, run git config receive.denyCurrentBranch false in Clone 1 so that it won't stop you from pushing to a checked out branch. false could also be warn or ignore.

    I'm not familiar with any git GUI, but I guess they support a bare clone and git config.