56 comments

[ 2.6 ms ] story [ 67.7 ms ] thread
Maybe I'm too old, but are there people that really didn't know that any ssh access is sufficient for using git?
Interesting. I am just trying to decide between self-hosting Forgejo and other options for hosting Git in own private network.
One note, xcode and maybe some other clients can't use http "dumb mode". Smart mode is not hard to set up, but it's a few lines of server config more than this hook.

TIL about the update options for checked out branch. In practise though usually you want just the .git "bare" folder on server

I've used Git over SSH for several years for personal projects. It just works with no additional overhead or maintenance.

Tip: create a `git` user on the server and set its shell to `git-shell`. E.g.:

  sudo useradd -m -g git -d /home/git -s /usr/bin/git-shell git
You might also want to restrict its directory and command access in the sshd config for extra security.

Then, when you need to create a new repository you run:

  sudo -u git git init --bare --initial-branch=main /home/git/myrepo.git
And use it like so:

  git clone git@myserver:myrepo.git
Or:

  git remote add myserver git@myserver:myrepo.git
  git push -u myserver main
This has the exact same UX as any code forge.

I think that initializing a bare repository avoids the workarounds for pushing to a currently checked out branch.

Just make the repository on the server side bare and you won't have to worry about checked out branches or renaming ".git" directory.
I remember the first time I tried git, circa 2006, and the first 3 commands I tried were:

    git init
    git commit -am Initial\ commit
    git clone . ssh://server/path/to/repo
And it didn’t work. You have to ssh to the remote server and “git init” on a path first. How uncivilized.

Bitkeeper and a few other contemporaries would let you just push to a remote path that doesn’t exist yet and it’d create it. Maybe git added this since then, but at the time it seemed like a huge omission to me.

this article is very bad advice. this way things are extremely brittle and there's a reason all those settings are disabled by default. you will lose data, save from very specific use cases

the vastly superior way is 'git bare' which is a first class supported command without hacky settings.

As a git user "not by choice" (my preference going for mercurial every single day), I never understood why git needs this distinction between bare/non-bare (or commit vs staging for that matter). Seems like yet another leaky abstraction/bad design choice.
I have been doing this for many years.

If you want a public facing "read only" ui to public repositories you can use cgit (https://git.zx2c4.com/cgit/about/) to expose them. That will enable others to git clone without using ssh.

I keep my private repositories private and expose a few public ones using cgit.

I tried this and it is never as smooth as described.

Why is GitHub popular? its not because people are "dumb" as others think.

Its because GitHub "Just Works".

You don't need obscure tribal knowledge like seba_dos1 suggests [0] or this comment https://news.ycombinator.com/item?id=45711294

The official Git documentation for example has its own documentation that I failed to get work. (it is vastly different from what OP is suggesting)

The problem with software development is that not knowing such "tribal knowledge" is considered incompetence.

People don't need to deal with obscure error messages which is why they choose GitHub & why Github won.

Like the adge goes, "Technology is best when it is invisible"

[0] https://news.ycombinator.com/item?id=45711236

[1] https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-...

I am surprised how little software engineers (even those that use) know about git.
(comment deleted)
There was a brief period when Google Cloud had support for hosting git on a pay-per-use basis. (I think it was called Google Cloud Repositories.) It had a clunky but usable UI.

I really preferred the idea of just paying for what I used -- rather than being on a "freemium" model with GitHub.

But -- as many things with Google -- it was shutdown. Probably because most other people do prefer the freemium model.

I wonder if this kind of thing will come back in style someday, or if we are stuck with freemium/pro "tiers" for everything.

My git "server" is a folder of bare git repositories in home directory which I share with Syncthing.

It'd be great if there was more specific support. But in practice? No problems so far.

  git clone ssh://username@hostname/path/to/repo
this is equivalent to:

  git clone username@hostname:path/to/repo
and if your usernames match between local and remote:

  git clone hostname:path/to/repo
(if the path has no leading /, it is relative to your home directory on the remote)
The proper way to do this to make a "bare" clone on the server (a clone without a checked out branch). I was doing this in 2010 before I even signed up to GitHub.
I feel like something was lost along the way.

    git init —-bare
will give you a git repo without a working set (just the contents typically in the .git directory). This allows you to create things like `foo.git` instead of `foo/.git`.

“origin” is also just the default name for the cloned remote. It could be called anything, and you can have as many remotes as you’d like. You can even namespace where you push back to the same remotes by changing fetch and push paths. At one company it was common to push back to `$user/$feature` to avoid polluting the root namespace with personal branches. It was also common to have `backup/$user` for pushing having a backup of an entire local repo.

I often add a hostname namespace when I’m working from multiple hosts and then push between them directly to another instead of going back to a central server.

For a small static site repo that has documents and server config, I have a remote like:

    [remote “my-server”]
    url = ssh+git://…/deploy/path.git
    fetch = +refs/heads/*:refs/remotes/my-server
    push = +refs/heads/*:refs/remotes/my-laptop
So I can push from my computer directly to that server, but those branches won’t overwrite the server’s branches. It acts like a reverse `git pull`, which can be useful for firewalls and other situations where my laptop wouldn’t be routable.
Beware of using this to publish static sites: you can accidentally expose your .git directory to the public internet.

I got pwned this way before (by a pentester fortunately). I had to configure Apache to block the .git directory.

This is definitely nice but it doesn’t really support the full range of features of Git, because for example submodules cannot be local references. It’s really just easier to set up gitolite and use that in almost the same exact way but it’s much better.
I do something similar. I create a bare repo on my dropbox folder or nas mount. Then checkout from bare repo file path to some place where I will be doing all the work.
The more I use git, the more I discover more depth to it.

So many features and concepts; it's easy to think you understand the basics, but you need to dig deep into it's origin and rationale to begin to grasp the way of thinking it is built around.

And the API surface area is much larger than one would think, like an iceberg

So I find it really weirdly low level in a way. Probably what is needed is is a higher-level CLI to use it in the most sensible, default way, because certainly the mental model most people use it with is inadequate.

Cannot emphasize this whole notion enough; Very roughly, Github is to git what gmail is to email.

It's mostly probably fine if that's the thing most of everybody wants to use and it works well; but also it's very unwise to forget that the point was NEVER to have a deeply centralized thing -- and that idea is BUILT into the very structure of all of it.

What is it with code on blog posts where fonts have uneven size and/or font types (e.g. italics mixed in with regular)? I see this from time to time and I wonder if it’s intentional.
How would I sync access, if more than one people ssh-pushes onto the git repo? I assume syncing be necessary.