|
1 | 1 | # Git |
2 | 2 |
|
3 | | -How to's concerning `git` in general, [`gitlab`][cern_gitlab], [`github`][github] and CI. |
| 3 | +How to's concerning `git` in general, [`gitlab`][cern_gitlab], [`GitHub`][github] and CI. |
| 4 | + |
| 5 | +## Github Commandline Access Quickstart |
| 6 | + |
| 7 | +This section explains the basic steps to get started with GitHub. |
| 8 | +Since HTTP access via password only has been disabled by GitHub for security reasons, it is necessary to activate a secure method. |
| 9 | + |
| 10 | +This aims to be as short and concise as possible, for more extensive information, [see the GitHub security documentation][github_security]{target=_blank}. |
| 11 | + |
| 12 | +### Setup SSH Access |
| 13 | + |
| 14 | +An easy way to access GitHub securely is to use SSH. |
| 15 | +This guides you through the basic steps, but [details can be found in the GitHub documentation][github_ssh]. |
| 16 | + |
| 17 | +#### Create SSH Key |
| 18 | + |
| 19 | +For this, create an SSH key pair locally using the email address associated with your GitHub account: |
| 20 | + |
| 21 | +```bash |
| 22 | +ssh-keygen -t ed25519 -C "[email protected]" |
| 23 | +``` |
| 24 | + |
| 25 | +When asked for a location, it makes sense to give it an easily identifiable name, to remember what the key is for. |
| 26 | +The file should be placed in `~/.ssh/`, unless you are on `afs`, in which case the `~/private/` directory should be used. |
| 27 | + |
| 28 | +```text |
| 29 | +~/.ssh/github_authenticate |
| 30 | +``` |
| 31 | + |
| 32 | +!!! tip "Passphrase" |
| 33 | + You can optionally provide a passphrase for the key, which will make it more secure. |
| 34 | + This way, even if someone else gets a hold of the private key file, they will not be able to access it. |
| 35 | + On the downside, you will be asked to enter the passphrase every time you want to use the key. |
| 36 | + **It is recommended, to use a passphrase** but as it is just an extra layer of security, you can keep it short and simple. |
| 37 | + |
| 38 | +This will create two files: `github_authenticate` and `github_authenticate.pub`. |
| 39 | +The `.pub` is your public key that you can share with others, |
| 40 | +while the other file is your private key and **should never be shared with anyone!** |
| 41 | + |
| 42 | +!!! quote "Keep it secret, keep it safe!" |
| 43 | + _Gandalf_, about private SSH keys (probably). |
| 44 | + |
| 45 | +#### Add the Public SSH Key to GitHub |
| 46 | + |
| 47 | +After creating the key, you need to add it to your GitHub account. |
| 48 | +Log into your GitHub account, click on your avatar and go to `Settings` → `SSH and GPG keys`. |
| 49 | +Then click on [++"New SSH key"++{.green-gui-button}][github_new_ssh_key]{target=_blank} and paste the contents of the `.pub` file into the `Key` field. |
| 50 | + |
| 51 | +Give it a resonable name in the `Title` field (which it will appear as in the GitHub interface) and leave the `Key type` as `Authentication key`. |
| 52 | +Then click on `Add SSH key` and you are done. |
| 53 | + |
| 54 | +#### Configure SSH to use the key |
| 55 | + |
| 56 | +Next, you need to tell your local SSH client to use the key you created to connect to GitHub. |
| 57 | +For that, add the following lines to your `ssh` configuration file (typically at `~/.ssh/config` on UNIX systems): |
| 58 | + |
| 59 | +```bash |
| 60 | +Host github.com |
| 61 | + HostName github.com |
| 62 | + User git |
| 63 | + IdentityFile ~/.ssh/github_authenticate |
| 64 | +``` |
| 65 | + |
| 66 | +or use for the `IdentityFile` field the path you chose earlier for the ssh key file. |
| 67 | + |
| 68 | +!!! warning "Username" |
| 69 | + It is important that the `User` is `git` and **not your git-username**! |
| 70 | + GitHub will identify you automatically based on the email address you used to create the SSH key. |
| 71 | + |
| 72 | +#### Test Access |
| 73 | + |
| 74 | +Now you can test that everything works by running the following command: |
| 75 | + |
| 76 | +```bash |
| 77 | +ssh -T github.com |
| 78 | +``` |
| 79 | + |
| 80 | +which should then display |
| 81 | + |
| 82 | +```text |
| 83 | +Hi <Username>! You've successfully authenticated, but GitHub does not provide shell access. |
| 84 | +``` |
| 85 | + |
| 86 | +#### Clone Repository |
| 87 | + |
| 88 | +When you clone a new repository, always use the SSH url |
| 89 | + |
| 90 | +```text |
| 91 | +git clone [email protected]:pylhc/omc3.git |
| 92 | +``` |
| 93 | + |
| 94 | +which you can find from the ++"Clone"++{.green-gui-button} button of the repository page on GitHub. |
| 95 | + |
| 96 | + |
| 97 | +!!! tip "Changing a Repository URL" |
| 98 | + In case you already have a repository cloned with the wrong URL, you can change it with `git remote set-url`, e.g.: |
| 99 | + |
| 100 | + ```bash |
| 101 | + git remote set-url origin [email protected]:pylhc/omc3.git |
| 102 | + ``` |
| 103 | + |
| 104 | + If you are not sure which url is currently set, you can always check it with |
| 105 | + |
| 106 | + ```bash |
| 107 | + git remote -v |
| 108 | + ``` |
| 109 | + |
| 110 | +### Setup HTTPS Access |
| 111 | + |
| 112 | +You can setup https access by creating and using a personal access token or a password manager. |
| 113 | + |
| 114 | +!!! note "Not yet documented" |
| 115 | + As we use SSH access, this section not yet written. |
| 116 | + Refer to the [GitHub documentation][github_https] for more information and maybe write up a quick howto. |
| 117 | + |
4 | 118 |
|
5 | 119 | ## Configuring Gitlab CI to Automatically Pull into AFS |
6 | 120 |
|
@@ -120,12 +234,11 @@ Whenever you are pushing now any commits to the `master` branch, the CI/CD will |
120 | 234 | *[CD]: Continuous Delivery |
121 | 235 | *[lxplus]: Linux Public Login User Service |
122 | 236 |
|
123 | | -[sshuttle]: https://sshuttle.readthedocs.io/en/stable/ |
124 | 237 | [new_account]: https://account.cern.ch/account/Management/NewAccount.aspx |
125 | 238 | [afs_services]: https://resources.web.cern.ch/resources/Manage/AFS/Default.aspx |
126 | 239 | [github]: https://github.com/ |
127 | 240 | [cern_gitlab]: https://gitlab.cern.ch/ |
128 | | -[cern_linux]: https://linux.web.cern.ch/dockerimages/ |
129 | | -[acc_models_repo]: https://gitlab.cern.ch/acc-models/acc-models-lhc/ |
130 | | -[acc_models_yml]: https://gitlab.cern.ch/acc-models/acc-models-lhc/-/blob/2018/.gitlab-ci.yml |
131 | | -[acc_models_docker]: https://gitlab.cern.ch/acc-models/acc-models-www/-/blob/master/_docker/Dockerfile_cern_cc7_base |
| 241 | +[github_security]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure |
| 242 | +[github_https]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#https |
| 243 | +[github_ssh]: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh |
| 244 | +[github_new_ssh_key]: https://github.com/settings/ssh/new |
0 commit comments