tags:

views:

80

answers:

3

I have a project hosted on GitHub and I would like to work locally on it. I have multiple Computers that need to access it and I would like to share code between them. However, I do not want all of these commits to go on GitHub, so a simple "clone and then just push/pull" approach does not suit.

Essentially, I want this:

[GitHub] --> [A Local Network Share] --> [PC1]
                                     --> [PC2]

So PC1 and PC2 should be able to push/pull to the local network share and thus share code between each other, and every once in a while I want to push those changes to my GitHub repository.

I'm a bit lost here - do I just create a branch? Or do I git clone from GitHub to my share and then git clone from my share to PC1 and PC2, which would result them only having 1 remote (the share) and the share only having 1 remote (GitHub)?

Edit: It's not for security - I don't mind when all the immediate commits go to GitHub, and I also don't want to prevent PC2 from accessing GitHub. It's more that I don't want to setup the whole SSL stuff and because I am someone who commits very very often (sometimes every few minutes - I use git commit as an extended undo function), and I want the code on GitHub always to be compilable.

Edit 2: The solutions here did not work for me yet :( So I do

git clone --bare [email protected]:foo/bar

on my server. This creates a clone. On my PCs, I git clone this repository - that step works fine, my PCs have a .git repository and my server is set up as a remote.

However, on the server, nothing is set up properly - there are no remotes added and i can't push from there. Adding a remote is easy using git add, but then how do I push? git status says it requires a work dir (which we don't have with --bare), and git push says "Everything up to date" even though it isn't (I made a change on PC1 and git pushed to the Server)

Creating the repository on the server without --bare means that it has it's own work dir, so when I git push from the PCs, the server does not pick that up (I'm guessing I somehow need git pull from the PCs, but I want to avoid that).

Am I missing a step here?

+3  A: 

The second solution should be enough.

  • Creating a fork would mean your intermediate stage would still be GitHub (a fork is a git clone on GitHub)
  • creating a branch does not solve anything in term of sharing code

If you make a git clone --bare myGitHubRepo.git on your share, and then clone that sharedRepo on PC1 and PC2, you have set up for each of those PC repo a natural destination for them to push/pull.

Edit by mstum: This approach works and is correct, but is missing a step. The bare clone on the server does not have any remotes setup. This needs to be done either with

git remote add origin [email protected]:user/Project.git

or every push from the Server to gitHub needs to be

git push [email protected]:user/Project.git
VonC
@Michael: thank you for the edit and the extra step.
VonC
A: 

Is this for security so that PC2 doesn't have access to push to github? For that, I usually set up multiple git remotes from my development machine. Developers that don't have push access to the main remote can push/pull to a separate remote. You can then pull their changes down to a different local branch and merge them in as you see fit.

Gattster
+1  A: 

This is quite achievable. First make a bare clone of the github repo:

git clone --bare git@github:foo \\network\foo

The repository is bare(doesn't contain working copy, this is to so that you can clone it locally and push to it).

Then on each PC you clone the network location:

git clone \\network\foo foo

You then work on each repository and make branches, commits etc and push them to the share. When you are ready to push to github, change into \\network\foo and push from there.

Igor Zevaka