How to setup Git on local network?
Asked Answered
T

6

24

I downloaded Git setup and trying to setup for computers in my network. I searched for the process but I found it for to host code on line on github.com. I found a few links but there is not the whole process.

I am aware for how to push and pull.

Tracheo answered 3/3, 2015 at 9:8 Comment(5)
What do you mean by whole process? Do you need the command to setup a server and clone the repo?Derbent
I installed GIT now I want create one central repository and access it via my other computers. But I don't how. I am aware for how to push and pull onlyTracheo
Which protocol do you want to use? There are http, ssh and git available, which all have different properties.Cita
http will be batter because I am aware it than other.Tracheo
Did you ever found out how to do it ? I am searching for the same thing. As someone with no knownledge at all of git, it is hard to find anything that starts from the beginning and has ALL the steps explainedAnemography
K
21

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
    
Kandace answered 3/3, 2015 at 10:7 Comment(4)
what does repo/path on add origin refer to? i cant seem to make it work it always errorKazim
@Kazim did you get anywhere with this? Having the same issue.Utopianism
@Utopianism yes! basically your git repo should always be "bare" then you clone that repo as a working branch to your working computersKazim
what software do I need on the server ? what software do I need on the development PC ? How to make them find eachother ? There are no answers in here, only more questions. Is there really no documentation that will help someone that has no knowledge at all of git that can get him started ?Anemography
D
15

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.

Donahoe answered 8/6, 2017 at 16:26 Comment(1)
[jack@nasa git]$ git daemon --base-path=/home/jack/git --export-all [11067] Could not bind to 0.0.0.0: Address already in useTate
D
9

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.

Derbent answered 3/3, 2015 at 9:18 Comment(0)
A
5

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

Anemic answered 12/11, 2021 at 20:20 Comment(0)
S
1

It is just easy as 1, 2, 3, 4:

1) Go to folder, where you want to initialize server(e.g: c:\temp).

2) Open git bash in this folder.

3) Type:

git init projectName --bare   // e.g => git init test --bare

well,You’ve just set up your server!

4) Choose where you want to initialize client repository and open git bash there.

Type:

git clone path/projectName  // e.g => git clone c:/temp/test

IMPORTANT! DO NOT FORGET TO CHANGE BACKSLASH (\) IN THE PATH TO DIRECT SLASH(/).

You can use this repository as usual and open it with your favorite git client.

connect to this server from another computer in local network:

(in windows 7) Firstly go to Control Panel > Network And Sharing Center > Change advanced sharing settings. Tick turn on network discovery.

Then go to folder where you have set up server and share it with users that you want to give permission for accessing it.

then Type:

git clone //ip/projectName   // e.g => git clone //192.168.11.125/test

I hope is useful.

Spain answered 24/11, 2019 at 4:28 Comment(4)
git is not recognized as an internal command. Please is there no documentation that has ALL the steps ?Anemography
@GuidoG, the main command is git init projectName with option --bare , that --bare Create a bare repository. If GIT_DIR environment is not set, it is set to the current working directory. the other steps is normally commands.Spain
and what software do I need ? I don't have git yet. I don't want to use git on the internet, I need git here at my local network and it should never ever connect to internet. So what do I need from software and how does it works ?Anemography
@GuidoG, the top solution only needed to install the git, ofcourse you can use the offline git server. for example Bonobo Git Server (for windows os). use this link for download: https://bonobogitserver.com/. download and create new website in local server and copy the downloaded file to your website and enjoy.Spain
P
0

From JJ-Brown's answer

Basically, you'll want to use git daemon.

For that, make sure to use Git 2.32 (Q2 2021): "git daemon"(man) has been tightened against systems that take backslash as directory separator.

See commit 9a7f1ce (25 Mar 2021) by René Scharfe (rscharfe).
(Merged by Junio C Hamano -- gitster -- in commit bde35a2, 08 Apr 2021)

daemon: sanitize all directory separators

Signed-off-by: René Scharfe
Acked-by: Johannes Schindelin

When sanitizing client-supplied strings on Windows, also strip off backslashes, not just slashes.

Pescara answered 11/4, 2021 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.