setting up git repository on local machine
Asked Answered
J

3

17

How can I setup a git repository on a local system ? (I am on a windoze box)

This is the setup I am trying to achieve: (everything is on my local machine)

  • host folder (which acts like central repository)
  • client folder

I want to do all my dev in the client folder. Once I am done, I'd like to push it to the host folder.


This is what I've done: (using git bash on windows)

  • cd d:/adinsert
  • mkdir host
    • cd host
    • git init

cd c:/

  • mkdir client
    • cd client
    • git init
    • git remote add origin d:/host // Added some files in client folder and commited them
    • git push origin master

When I push stuff to origin, git spits a lot of remote errors. However, when I make my host a bare git, it pushes successfully.

I don't understand the difference between regular git and bare git. From the manual, all I understood was, bare git is used for storing deltas and when you don't want to store original files. However, I'd like to store the files in host. How can I do that ?

Justinajustine answered 23/3, 2011 at 22:40 Comment(0)
D
14

The difference between a "regular git" and a "bare git" is that a bare repository does not have a working directory. You should never push into a regular git repository, as you may run into problems that are hard to recover from. Always push into a bare repository.

If you want to have a "host" where copies of your files do appear, then set up a third repository, cloning from the host one. Whenever you want to update the host files:

  • git push from your working directory to update the main repository
  • git pull from your host directory to pull from the origin

You can even set up a post-commit hook on the bare repository to automatically do the second step.

Diddle answered 23/3, 2011 at 22:46 Comment(4)
Here is how my setup looks like: I have two hard disks, one of which i use for backups. I come from a background in subversion, where the main files are always present on the server. I'd like to do something similar with git, where I can create one git repository on the host, add files to it, pull these files to my client folder, make changes and upload the new updates files back to host. Is this possible ?Justinajustine
I am in-essence trying to do something similar that git-hub does, where you clone the repository, make the changes on your local machine and upload it back to github. (in my case, its not github, but another folder)Justinajustine
@brainydexter: Sure, just make two repositories, one for your working copy and another for your "master" copy (you can think of it as "the server" in Subversion terms). The master one will be a bare repository, so you can push into it.Diddle
This answer was helpful for me in achieving/approaching the desired git-hub behavior.Procreate
O
3

In your client directory you have will notice a .git directory. A bare version is basically just that .git directory contents without a working copy.

Easiest thing to do would be to clone it (vs trying to setup another repository):

From c:/ call:

git clone d:/host client

This says clone the 'host' repo and store it under a folder called 'client'.

Ormazd answered 23/3, 2011 at 22:46 Comment(0)
B
1

Don't create a new git repo in the client folder, clone the host repo

cd client
git clone d:/adinsert/host
Blizzard answered 23/3, 2011 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.