How to add a Git Remote Repository on your private server

- by

You can backup your local Git repos to a private server server, either on your own network or via the internet. All you need is access to the server and a bare repository, then connect it as remote URL and you can push data to and from it. It’s a great way to share your data and collaborate with others, without involving third part companies like Github. Let me show you how to do it.

My remote server is a Linux box on my own network. I have a local repository already and I’m ready to connect it to the remote, which needs to have Git installed on it.

On the Git Server, pick an empty folder and initialise the remote like this:

git init --bare

Now on the client, inside the existing repo, we can connect the remote via user/path combo. Let’s say my server’s IP is 1.2.3.4 and my user name is “jay”, and the full path to my remote is “/home/remotepath”I’d connect it like this:

git remote add origin jay@1.2.3.4:/home/remotepath

Git will ask for your password and come back with an “enumerating objects” message. Instead of a numeric IP, you can also use a domain name (like user@server:/path).

This does not actually transfer any data, it only seems to establish the connection between the two repos. To move data to the remote, we push/publish a branch. Say my active branch is called “master”, I can do it like this:

git push origin master

It’ll take a moment depending on the size of the repo and the connection speed between the two. “git push” is the command, “origin” is the destination, and “master” is the branch you’d like to publish.

Once connected, you can use the GitHub for Desktop app to push to your remote, commit changes and publish/merge branches too.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.