diff options
| author | Luke Smith <luke@lukesmith.xyz> | 2022-06-26 01:41:11 +0000 |
|---|---|---|
| committer | Luke Smith <luke@lukesmith.xyz> | 2022-06-26 01:41:11 +0000 |
| commit | 2d5ab8e1cedc117219f0811148226ab439e8d85b (patch) | |
| tree | 13f4e150efa669714b485fd483f466de80237ec4 | |
| parent | e9f7a69ce4604873e24ab10514c9dd6aea220f86 (diff) | |
git tutorial fixes, fix #158
| -rw-r--r-- | content/cgit.md | 2 | ||||
| -rw-r--r-- | content/git.md | 106 | ||||
| -rw-r--r-- | content/gitea.md | 18 |
3 files changed, 58 insertions, 68 deletions
diff --git a/content/cgit.md b/content/cgit.md index 8f239c6..70104a9 100644 --- a/content/cgit.md +++ b/content/cgit.md @@ -11,7 +11,7 @@ Software that allows browsing git repositories through the web. Note that Cgit is a read-only frontend for Git repositories and doesn\'t have issues, pull requests or user management. If that\'s what you want, -consider installing Gitea instead. +consider installing [Gitea](/gitea) instead. ## Installing cgit and fcgiwrap diff --git a/content/git.md b/content/git.md index f7cb6b5..e186cd0 100644 --- a/content/git.md +++ b/content/git.md @@ -35,18 +35,18 @@ apt install git We don\'t need any additional software, `git` itself ships with everything needed to host a remote repository! -## Creating bare repositories +## Creating a git user -For each repository you want to host, you will need to manually create -what\'s called a \"bare\" repository on your server. These hold all the -commits and any other git data needed for your repository, but without -an expanded \"index\" in which you can just browse all the files of a -certain commit in the file system. +To prevent exploiting your system, services should usually be run under another +user that can only affect the relevant parts of the server. Let's create a user +for git. -These repositories need to be owned by the `git` user, and you should -probably pick a directory where you will store them all. One sane choice -is under `/srv/git/`, and we will use this as the example directory for -the rest of the tutorial, but any other path will do as well. +```sh +useradd -m git -d /var/git -s /bin/bash +``` + +The `git` user's home directory will be `/var/git` and we also set the default +user shell as bash instead of sh for ease when on the command line. ### Become the git user and create the directory @@ -54,15 +54,11 @@ If you\'re logged in to your server as root and have `git` installed, you can become the `git` user by executing ```sh -su git +su -l git ``` -Now navigate to/create your desired directory, for example - -```sh -cd /srv -mkdir git -``` +The `-l` option should put us in `git`'s home directory, but you can `cd +/var/git` otherwise. ### Create the repo @@ -72,7 +68,8 @@ Now you can create the bare repository with git init --bare my-repo.git ``` -By convention, bare repository names end with \".git\". +By convention, bare repository names end with \".git\". (A bare repository is +just one without the file index, (i.e. the familiar browseable file structure).) Repeat the above command for any other repositories you want to host. @@ -80,64 +77,55 @@ Repeat the above command for any other repositories you want to host. ### Set up SSH login for the git user -You will need to be able to login remotely via `ssh` as the `git` user -we\'ve used before. To do this, you will either need to set up a -password for the `git` user by running `passwd git`, or copy your public -SSH key from your local machine to `/home/git/.ssh/authorized_keys`. See -the [SSH keys instructional](/sshkeys) for details (just log in as -`git` instead of `root`). +Git uses SSH to connect to a server, and we will definitely want to use an SSH +key pair that we authorized. This is not only most secure, but also easiest +since we don't need to put in our password whenever we pull or push. -### Syncing a new repository with your server +There is a brief article [on setting up SSH keys](/sshkeys). We need to do +exactly that, but for the `git` user, instead of the default `root` user. Note +that if you want to upload your SSH key directly to the git user as in that +tutorial, remember to run `passwd git` to give the git user a password so you +can log in. -If you\'ve just created a new repository on your local machine, you will -need to tell `git` where the remote repository is to be able to sync -with it (using commands like `git push` or `git pull`). We do this by -defining a \"remote\" for your repository. +If you've already set up password-less SSH log-ins for root (and disabled SSH +password authentication), you can run the following commands as root, which +will copy over your authorized key to the git user as well. -A remote is just a named URL remembered in your repo\'s configuration. -So we need a name and a URL. By convention, the \"main\" remote is -called \"origin\". The URL has the format `user@host:path`, where: +```sh +mkdir /var/git/.ssh # Create the required directory. +cp ~/.ssh/authorized_keys /var/git/.ssh/ # Copy over the authorized key. +chown git:git -R /var/git/.ssh # Make the created directory and contents to be owned by the git user. + +``` -- `user` is `git`, the `git` user we\'ve already worked with before. -- `host` is your domain name. Alternatively you could even use your - server\'s raw IP address. -- `path` is the absolute path to the repository on the server, in our - example `/srv/git/my-repo.git` +### Syncing a new repository with your server -So, to create a new remote, run: +How that we've set that up, we can push a repository we have on our computer to +that newly created bare repo. First, on our local computer, we run a command like this: ```sh -git remote add origin git@yourdomain.xyz:/srv/git/my-repo.git +git remote add origin git@example.org:my-repo.git ``` -Now you\'ll be able to run `git push origin master` to push your commits -or `git pull origin` to pull from the remote. +Note some of the things you will change: -### Syncing an existing repository +- `example.org`, obviously is a stand-in for your domain name. +- `my-repo.git` is the name of the repository, but it is also the relative location of it. Since it is in the `git` user's home directory, we don't need anything else, but if you decide to put a git repository elsewhere---like in `/var/www/git/stuff.git`, you can provide that absolute file location instead. +- `origin` is a unique name for your remote repository. Since "origin" is probably already used if you are using Github or another service, you'll want to change this to whatever you want. Could be `myserver` or `vps` or `own`, as long as it is unique. -If you\'ve already set up your local repository to sync with a service -like GitHub it probably already has a remote called \"origin\". You can -see your repo\'s remotes with: +Once you run that command successfully to add a new remote repository, and also assuming you change `origin` to let's say the more unique `personal`, you can push your local git server as expected: ```sh -git remote -v +git push personal master ``` -You can follow the above instructions, substituting an arbitrary other -name other than \"origin\" to create a differently named remote, e.g. - -```sh -git remote add vps git@... -``` +That's all a git server is! Very simple. -Now you\'ll be able to push/pull with `git push vps master` and -`git pull vps`, respectively. +If you want a minimalist front-end to a git server, follow our guide on [cgit](/cgit)! -Or, to completely sever ties with your centralized git provider, first -remove the original origin with: `git remote remove origin` and then -follow the instructions as above. +If you want a large and user-friendly Github-like site for your git projects, follow our guide on [Gitea](/gitea)! ## Contribution -- Martin Chrzanowski \-- [website](https://m-chrzan.xyz), - [donate](https://m-chrzan.xyz/donate.html) +- Martin Chrzanowski \-- [website](https://m-chrzan.xyz), [donate](https://m-chrzan.xyz/donate.html) +- Edits and fixes by Luke. diff --git a/content/gitea.md b/content/gitea.md index 16a722e..685c8cb 100644 --- a/content/gitea.md +++ b/content/gitea.md @@ -6,18 +6,20 @@ tags: ['service'] short_desc: "A fully-featured Github-like git website for serious software projects and communities." --- - -Gitea allows you to self-host your git repositories similar to [bare repositories](/git), but comes with additional features that you -might know from GitHub, such as issues, pull requests or multiple users. -Its advantage over GitLab---another Free Software GitHub clone---is that -it is much more lightweight and easier to setup. +Gitea allows you to self-host your git repositories similar to [bare +repositories](/git), but comes with additional features that you might know +from GitHub, such as issues, pull requests or multiple users. Its advantage +over GitLab---another Free Software GitHub clone---is that it is much more +lightweight and easier to setup. Head over to [gitea.com](https://gitea.com) to see what it looks like in practice. -Although Gitea is lighter than Gitlab, if you have a VPS with only 512MB -of RAM, you will probably have to upgrade. Gitea is more -memory-intensive than having just a bare git repository. +Although Gitea is lighter than Gitlab, if you have a VPS with only 512MB of +RAM, you will probably have to upgrade. Gitea is more memory-intensive than +having just a bare git repository. If you just want a minimalist browseable git +server without issue tracking and pull requests, install [cgit](/cgit) +instead. ## Installing Gitea |
