Setting up a Git server in three simple steps

Andrew Montagne 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 r... [Read Full]
markdown guide

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 ?


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.


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.


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.


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.


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. 👍


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...


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. 😿


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


How do you share git repositories with this solution?


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.


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.

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.

code of conduct - report abuse