David B
David B

Reputation: 3581

Setting-up local git repository

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.

Upvotes: 16

Views: 32859

Answers (3)

Fwolf
Fwolf

Reputation: 691

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:

Upvotes: 17

Litmus
Litmus

Reputation: 10996

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

Upvotes: 3

Greg Gauthier
Greg Gauthier

Reputation: 1436

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

Upvotes: 2

Related Questions