13

I am a fan of using GitHub as my project file repository. But it interest me more if I am able to create a repository on this computer on a different directory path. Then clone that create repository on my new working directory.

I was planning to make a GitHub locally. I've been searching about this and many return that I should use gitolite and many more instead. The problem I am using Windows and I want to do all the steps using command line.

What command lines should I enter to create a repository on a different directory other than the working directory and be able to clone that repository to other terminals within the local network.


LINKING TERMINAL to Windows Host

I have created a repository directory pathed to Users\username\GIT\project.git. I am trying to link my terminal using the command line git clone file://{IPv4 server address}/Users/username/GIT/project.git returns

fatal: '/{IPv4 server address}/Users/username/GIT/project.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

How can I resolve this? I my host is running on Windows 7 and my connecting terminal(s) will be using Ubuntu 12.04 LTS and MacOS Mavericks.


UPDATE TRACK

  1. Updated my question body. I don't know what steps should I follow.
  2. Inserted LINKING TERMINAL to Windows Host question for repository sharing over local network.
David B
  • 3,269
  • 12
  • 48
  • 80
  • I suggest you simply use gitolite instead. You will probably run into issues with ssh keys and permissions as well. – Renato Zannon Nov 07 '13 at 15:40
  • have you checked out http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server ? – asifrc Nov 07 '13 at 15:40
  • @asifrc is this applicable if the server is Windows? – David B Nov 07 '13 at 15:43
  • 1
    lol nope.. I was going to ask. Yeah, developing on windows can suck sometimes (I'm torturing myself with Windows 8 :/ ) I'm currently looking into windows solutions and I'll let you know what I find :) – asifrc Nov 07 '13 at 15:46
  • Have you looked into http://bonobogitserver.com/ ? It looks promising.. ( [github repo](https://github.com/jakubgarfield/Bonobo-Git-Server) ) – asifrc Nov 07 '13 at 15:55
  • @asifrc. Look like it. But as I said, is there a way to do all of this manually? – David B Nov 07 '13 at 16:08
  • I have updated my question. Sorry for the change of the question body. I really don't know the steps to make this happen. – David B Nov 12 '13 at 16:56
  • Pretty sure gitolite depends on ssh and ssh keys. You might need to install an ssh daemon and/or cygwin. After that it should be doable. – Thom Wiggers Nov 12 '13 at 17:02
  • Why Github locally? Github is an online service. Every directory which has `.git` subdirectory created by `git init` command is a full-featured repository. It has full history, branches etc. You may clone it if you want, push to it. There is nothing special in Github repositories (except great www interface). They are simply hosted remotely. There is nothing strange in `git clone ~/repo1 ~/repo2`. – skalee Nov 12 '13 at 17:09
  • @ThomWiggers ssh daemon can be a solution. can you add your answer with the steps needed adding the steps to configure ssh both on server (OS: Windows) and terminal regardless of OS. – David B Nov 12 '13 at 17:21
  • @skalee true GitHub is an online service and I stand corrected there. But I wanted to create a git repository locally . Can you provide your answer? – David B Nov 12 '13 at 17:22

3 Answers3

15

Maybe you're asking simple way to create git repo and local clone ?

  1. Create git repo using git init --bare
  2. Clone from other place using git clone --local /path/your/local/repo/

For local network, windows share or other file share may work.

But, the simple way just work, not best or suitable way. there aren't pull request, issue track, privilege control feature on GitHub. For manage git commit or other complicated work, you need a manage system, such as gitolite, gerrit, some may not work on windows system.

If you only need a free private repo, you an use bitbucket.

Clone from windows share:

git clone file:////{IPv4 server address}/share_name/path_to_your_.git_dir

On host computer, you must share repo dir with a 'share_name', eg: parent dir of repo.git

See:

Community
  • 1
  • 1
Fwolf
  • 671
  • 4
  • 8
  • Right on the dot. Yet I can not follow you about windows sharing like any other answers. Anyways, (I know this may seem to be off-topic) a local based of bitbucket or GitHub for git management (JIRA, etc.)? – David B Nov 18 '13 at 05:09
  • It seems you are not very familiar with git, so I don't suggest you to build local git mangement system such as JIRA. Pure git can create local repo and do pull/commit/push locally, windows share (link with driver letter, eg g:\some\dir) will work same as in you own computer. If you learn more about git, this will more easy to choice. – Fwolf Nov 18 '13 at 10:44
  • If you knew few about git(especially in windows platform), manage a local git repo may give you more problem later, so use a online private git service maybe the right choice for you now. – Fwolf Nov 18 '13 at 10:47
3

If I read your problem statement correctly, You can simply clone a local git repo into another folder by using the --local switch on the clone command like this

git clone --local /git/source_repo/project /home/username/workdir/project

where

/git/source_repo/project is the safe copy of the repo (call it your personal GitHub if you like).

and

/home/username/workdir/project is your working folder. It can be any folder where you want to make frequent commits

Switches explained:

--local

When the repository to clone from is on a local machine, this flag bypasses the normal "git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. The files under .git/objects/ directory are hardlinked to save space when possible.

If the repository is specified as a local path (e.g., /path/to/repo), this is the default, and --local is essentially a no-op. If the repository is specified as a URL, then this flag is ignored (and we never use the local optimizations). Specifying --no-local will override the default when /path/to/repo is given, using the regular git transport instead.

To force copying instead of hardlinking (which may be desirable if you are trying to make a back-up of your repository), but still avoid the usual "git aware" transport mechanism, --no-hardlinks can be used.

--no-hardlinks

Optimize the cloning process from a repository on a local filesystem by copying files under .git/objects directory.

see documentation for more details

Update 1:

For setting up a Git Server on Windows, you can try this commercial (open source) software called GitStack.

Useful GitStack resources:

  1. GitStack Installation Instructions
  2. Link to source code of GitStack on Github
Community
  • 1
  • 1
Litmus
  • 10,558
  • 6
  • 29
  • 44
  • if you are using full paths for both source and destination, it does not matter where you execute the command. I have added more description to the answer above. – Litmus Nov 12 '13 at 17:26
  • Okay. But how about linking my terminals to the created repository via SSH or other protocols. – David B Nov 12 '13 at 17:37
  • Which terminals? you mean from other machines? If you want to set up a `git` server, it is better to use a non-windows platform. Not that it cant be done on `windows`, but `windows` support for `git` is pretty much an after-thought (remember Linus Torvalds is the creator of both Git and Linux). Not worth the effort. If you are still keen, google for `msysgit` or [visit this](http://msysgit.github.io/) – Litmus Nov 12 '13 at 17:41
  • Even if I make a non-Windows virtual environment as git server for the local network? – David B Nov 12 '13 at 17:48
  • That you can. You can use a [vagrant box](http://www.vagrantup.com/) to host your `git` server and make it accessible to other machines on your network. You can also try [Bitnami Stack for GitLab](http://bitnami.com/stack/gitlab/installer) to get an almost `github` like experience on your local lan – Litmus Nov 12 '13 at 17:51
  • Here is the [link to GitLabHQ](http://gitlab.org/) If you wish to explore more on this. It is open source, works great on Ubuntu. – Litmus Nov 12 '13 at 18:02
  • are there other options for me to consider? Like using VirtualBox, etc.? VM can take up memory heap, thus, slowing down my computer performance when coding. – David B Nov 13 '13 at 02:07
  • of course. Vagrant uses VirtualBox (or vmware) and runs guest OS in headless mode by default, thus requiring relatively less resources. Bitnami stack is also available as a ready to use VM image. You can consider utilizing AWS free tier to get a micro instance for free on amazon cloud. – Litmus Nov 13 '13 at 02:41
  • I have updated my answer hoping we could use native command line (without any third party software). – David B Nov 18 '13 at 16:29
  • if `\Users\username\GIT\` is your webserver DocumentRoot, then you can use `http://{IPv4 server address}/project.git` as git url. Otherwise, you will have to set up SSH server and use `ssh://{IPv4 server address}/Users/username/GIT/project.git`. You CANNOT use `file://{IPv4 server address}/Users/username/GIT/project.git` since `file://` can only reference a local file (on the local file system) – Litmus Nov 18 '13 at 16:42
1

To create a local bare repository, the command is actually pretty simple:

git clone --bare my_project my_project.git
Initialized empty Git repository in /my/projects/my_project.git/

As long as you're using these locally (say, from a USB attached storage device or something), that's really all there is to it. You would just point your commands at that repo, for cloning, pushing, pulling, etc. Though, one might ask why you'd want to do such a thing.

These instructions are for getting setup on a server, but I found these instructions really helpful for creating local repos as well: http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server

Greg Gauthier
  • 1,336
  • 1
  • 12
  • 25
  • Sorry for the confusion, it would be from the parent of where your working copy of the repo is. So, if I have `/projects/myproject`, and I want to create an "official" bare repository, I would `cd /projects` and then enter `git clone --bare myproject /location/for/bare/myproject.git`. Git will look for a `.git` directory in the directory specified in the first argument. – Greg Gauthier Nov 12 '13 at 17:42
  • Great, how bout linking my terminals to the created repository? – David B Nov 12 '13 at 17:49
  • @Dr.Java - To clone from another machine, you would need to make sure the other user has a user account on your machine, and that ssh is setup, and that the user is enabled for ssh. Then they could execute a normal git clone command, pointing at the bare repo you created. Using the example above, like this: `git clone {the_user}@{your-ip-address}:/location/for/bare/myproject.git` – Greg Gauthier Nov 12 '13 at 19:17
  • if I understand it correctly, I need to setup/create a user account on my Windows GIT Host to match the user account to be used by my terminals? Do I still need to configure SSH for this to work (especially on the server side)? – David B Nov 13 '13 at 02:05
  • For this approach to work, yes (as far as I understand Git). The HTTP approach requires setting up the git-daemon, I believe, and I'm not sure that's available for Windows. You'd probably have to also set up Cygwin for that. Alternatively, you could put your repos on a network shared drive, as this source suggests: http://elegantcode.com/2011/06/18/git-on-windows-creating-a-network-shared-central-repository/ – Greg Gauthier Nov 13 '13 at 02:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41069/discussion-between-greg-gauthier-and-dr-java) – Greg Gauthier Nov 13 '13 at 03:34
  • I have updated my question without using any third party software. – David B Nov 18 '13 at 16:29