3

I have just started a new git project that is so far stored on my local Mac. Now that the project has a few revisions checked into it, I would like to push these changes to a network location (I have a Time Capsule in my local network, where I wish to maintain the master copy of all my code, instead of pushing to Github).

I'm currently reading the Pro Git book, but there are some points that aren't explained. The main point that I need explaining is what's the difference between a git project and a git repository; or are they the same thing?

This is the structure I would like.

my remote root location (over local) for all my projects will be:

/Volumes/Capsule/dev/github/...

under here I would like my projects, eg:

/Volumes/Capsule/dev/github/canary
/Volumes/Capsule/dev/github/guinea

So would canary & guinea be repositories or projects?

I know you can add a remote using the command of the form: git remote add

The example I'm working from is:

git remote add local_proj /opt/git/project.git

but what is project.git? (or is this a typo? shouldn't it be .../project/.git)

My canary project root folder is ~/dev/github/canary and the git administration files are in ~/dev/github/canary/.git

so what is the equivalent command for the canary project?

I tried the following from ~/dev/github (canary is in this folder)

git remote add canary /Volumes/Capsule/dev/github/canary.git

but got this error message:

fatal: Not a git repository (or any of the parent directories): .git

The reference that you specify in the git remote add, is that per project or per repository? Would I have 2 difference references for canary and guinea, or is there just 1 remote locations under which both canary and guinea be referenced?

Plastikfan
  • 3,674
  • 7
  • 39
  • 54
  • I just realised that the reason the git remote add canary failed, was because I wasn't inside the canary project. It succeeded when I changed into canary, so now I have a remote name of 'canary', but I can't push to due to access rights. But my question still stands, is 'canary' a reference to the project or repository? If I set up another project at the same remote location, will the reference I use be a different one? – Plastikfan Feb 22 '15 at 19:11
  • Interested in installing a [Git Server Like GitHub](http://stackoverflow.com/questions/5507489/git-server-like-github)? – fructurj Feb 22 '15 at 19:12
  • I just tried to create the remote location manually, and this git inited that folder. I also checked the access rights and I have full access, but the push still fails, so not sure what is wrong. – Plastikfan Feb 22 '15 at 19:30
  • if you need a simple local network-based installation you don't need a specialized git server. I just need a server machine in your network, on which you initialize a repo ([--bare option](https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init) will work best of all. Then select [an appropriate protocol](http://git-scm.com/book/ch4-1.html) to provide access to it from your development machine (**local**, or **ssh** will work for example) and clone a repo on your developer machine. That's it. – Andrey Pesoshin Feb 22 '15 at 19:52
  • 1
    I don't want to use another server. I thought you could use a network disk as a remote repositry. Is that not the case. Does the remote location have to be another computer as opposed to a network disk? – Plastikfan Feb 22 '15 at 20:35

1 Answers1

4

So, after much experimentation I found the solution to this quite simple problem that doesn't appear to be explained adequately anywhere in a single location.

(There is potential for confusion with 'local' terminology. For the purposes of this article 'local' is just referring to local location of a project on mac's internal disk as opposed to a network location. 'Local' (capitalised 'L'), refers to the protocol. The remote repository will be created using protocol Local, as opposed to ssh or http for example).

local project location: ~/dev/github/...
remote location: /Volumes/Capsule/dev/github/...

So just to re-iterate, the problem is a project needs to be pushed to a remote location; that remote location/repo doesn't actually exist yet.

The first thing you have to do is create the remote location. So continuing the example above, I need to create the remote canary project at the remote location. Also, since this remote location is not a working directory, it should be created as a bare repository:

1) Create the remote folder:

cd /Volumes/Capsule/dev/github
mkdir canary.git

(NB as indicated on page 132 in Pro Git 2nd Ed, bare repositories are named with .git suffix, eg canary.git)

2) Initialise the remote location:

cd canary.git/
git init --bare --shared
Initialized empty shared Git repository in /Volumes/Capsule/dev/github/canary.git/

(The --shared option is required to ensure that the correct write permissions are created properly on the remote path allowing you to push to it without access errors occuring)

The remote bare repo is now created and can now being configured as a push target for your local existing project (canary).

3) Add the remote repo to local project canary

go back to your local project

cd ~/dev/github/canary

add the remote using git remote add

git remote add origin /Volumes/Capsule/dev/github/canary.git

and check what you've done

git remote -v
origin  /Volumes/Capsule/dev/github/canary.git (fetch)
origin  /Volumes/Capsule/dev/github/canary.git (push)

'origin' is now the remote reference to your local canary repo.

4) Push local canary project to the remote

git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /Volumes/Capsule/dev/github/canary.git
 * [new branch]      master -> master

And there you have it, a local project pushed to a new Local remote location.

Plastikfan
  • 3,674
  • 7
  • 39
  • 54