How to setup Git on local network?

You have to create a repository on the server side. Go to the folder which should be the repository and execute:

git init --bare

Then you have to clone the repository on your client with:

git clone user@gitserver:/path/to/your/folder

Watch this for further information.


To create a new repository

  1. Create directory using git bash or create manually
  2. User following commands to create repository

    cd /repo/path/projectname.git
    git init --bare
    
  3. After initialize directory share the directory and grant all permission to local group

To create a local workspace

  1. Create another local repository for local user or other computer use following commands in same order

    cd ~/workspace/local/path
    
    git init
    
    git clone user@gitserver:/path/to/your/folder
    
    git add origin repo/path 
    
    git add .
    
    git status
    
    git commit
    

If you're asking about how to connect to a repository hosted by another computer on the same network, take a look at this StackOverflow thread.

Basically, you'll want to use git daemon. If you just need to set up a single repository, that's one line from each machine:

Server:

git daemon --base-path=/path/to/repo --export-all

Client:

git remote add LocalServerName git://<serveraddress>/

or

git clone git://<serveraddress>/

where <serveraddress> is some reference to that machine (IPv4, IPv6, .local, etc.). You can also specify --verbose for the daemon command for more detailed output.

I think, also, you could have --base-path point to a folder with many repositories, and that would let you specify which project you wanted on the client-side like so:

git daemon --base-path=/path/to/all/repos

git remote add ServerName git://<serveraddress>/MyProject/

Be advised: using --export-all will let any computer on the network pull from your repo.


create a server folder [repository] with .git extension in [computer 1]

mkdir folder.git
cd folder.git
git init --bare

in another computer in your network [computer 2]

mkdir myApp
cd myApp
git init
git add .
git commit -m "first commit"
git remote add origin [email protected]:/home/alex/folder.git
git push origin master
  • replace alex with the name of your username
  • replace 195.185.1.65 with your IP address from server computer

any computer in your network can access the repository [folder.git]

git clone [email protected]:/home/alex/folder.git
  • this is going to download a directory with the name folder, just like if you were doing it from GitHub.
assumptions
  • git uses ssh protocol by default for connecting between computers.
  • you can setup ssh by doing ssh [email protected] from remote computer, and it's going to ask you for permission to connect, write yes. I think it's just easier than to copy your public key to the server authorized key file at /home/.ssh/authorized_keys.
  • remember to replace alex with your username, also 195.185.1.65 with your IP address.

from source Git--Setting Up the Server