DEV Community

Setting up a Git server in three simple steps

Andrew O'Rourke on April 02, 2017

This is a little thing I discovered which is pants-on-head simple to do, but is probably not known by a lot of people: How to host your own Git rem...
Collapse
 
doshirae profile image
Doshirae

I have a question
For now, I have my remote set to be a github repo, so I push to it, then ssh into my server where my project (a discord bot) is, and then pull

Does setting my server as the remote prevents me from pulling each time ?

Collapse
 
andrew profile image
Andrew O'Rourke

I'm not entirely sure what you mean, but it's worth mentioning that you can have more than one remote for a git repo. You can pull and push from whichever remotes you want.

Collapse
 
doshirae profile image
Doshirae

Ohw
How can you do that ?

Thread Thread
 
bhaveabhay profile image
Abhay Bhave

Well, "origin", though default, is just a name. Name of a "Remote repo" wherever that is ;)

Git is great because it's f simple!

You can have multiple remotes, and the situation will be like github forks, only may differ from it in permissions.

I think auth and permissions are not git's direct responsibility, though I many be wrong about it.

Collapse
 
shalotelli profile image
Sha Alibhai

My version of "lazy deployments" is SSH'ing in to the remote serve, git cloning the project from github and then pushing and fetching each time there's a change. If i set up the server as a remote and pushed to it instead, and then set up a post commit hook to restart pm2 for example (node process manager) can you see that introducing any additional risk? Seems easier especially in smaller projects rather than SSH'ing in to the server each time and fetching the latest changes. Im thinking the server would be something other than origin so that i could still keep a safe remote copy elsewhere...

Collapse
 
andrew profile image
Andrew O'Rourke

The remote is a bare repository, it doesn't have a working copy, so I don't think what you're thinking of is possible; at according to my (likely limited) knowledge of Git. 😿

Collapse
 
foresthoffman profile image
Forest Hoffman

This is really cool! I've been contemplating doing this as an alternative to Bitbucket, for projects that I don't want to open-source.

Collapse
 
chrischarabaruk profile image
Chris Charabaruk

You don't need to open source stuff you put on Bitbucket. They support unlimited private repositories, although there's a five account limit on who can access them if you don't pay them.

Collapse
 
foresthoffman profile image
Forest Hoffman

Oops, I mis-worded my comment. I had meant to say that I was considering self-hosting a git-server, rather than relying on Bitbucket for my own private repositories. Of which I have a few.

Nice catch. 👍

Collapse
 
jugmac00 profile image
Jürgen Gmach

How do you share git repositories with this solution?

Collapse
 
fuzzy76 profile image
Håvard Pedersen

The same way you'd share files on any Linux server. For a development team, I'd probably make a team account and add all users keys to that user.

Collapse
 
jugmac00 profile image
Jürgen Gmach

Right, but then the time comes when not all repos should be accessible to all developers. And access by SSH means more than just be able to do a git push/pull/clone. Those "easy" solutions tend to get quite problematic over time.

Thread Thread
 
andrew profile image
Andrew O'Rourke

You can change the shell for the git user to git-shell, which will prevent them from running anything but git commands (As far as I'm aware that's all GitHub does on their servers).

If you're after something that doesn't give devs access to certain repos, you can always symlink like Håvard Pedersen mentioned; although if you're wanting something like that, you're probably better off with a solution like GitLab anyway.

Collapse
 
erinlmoore profile image
Erin Moore

I didn't realize it was this easy 😻 Thanks!

Collapse
 
apedroed88_60 profile image
Antonio Pedro Edmilson Carvalho do Nascimento

It's realy simple, but is more usual have a server with gogs or git lab installed

Collapse
 
meilon profile image
Christian Arnold

I love GitLab! And their CI is so easy to setup!