@@ -26,12 +26,11 @@ Any upload to and from GitHub requires you to authenticate yourself. GitHub
...
@@ -26,12 +26,11 @@ Any upload to and from GitHub requires you to authenticate yourself. GitHub
used to allow authentication with your account and password, but this is no
used to allow authentication with your account and password, but this is no
longer the case - using SSH keys is favoured instead. Knowing exactly what these
longer the case - using SSH keys is favoured instead. Knowing exactly what these
are is not necessary to get them working, but we encourage you to read the box
are is not necessary to get them working, but we encourage you to read the box
below to learn more about them! GitHub has excellent, platform-specific
below to learn more about them!
instructions both on how to [generate](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
and [add](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
{ width=600px }
SSH keys to your account, so please use them before moving on!
!!! quote "SSH keys and authentication"
??? quote "SSH keys and authentication details"
Using SSH (Secure Shell) for authentication basically entails setting up a
Using SSH (Secure Shell) for authentication basically entails setting up a
pair of keys: one private and one public. You keep the private key on your
pair of keys: one private and one public. You keep the private key on your
local computer and give the public key to anywhere you want to be able to
local computer and give the public key to anywhere you want to be able to
...
@@ -56,6 +55,30 @@ SSH keys to your account, so please use them before moving on!
...
@@ -56,6 +55,30 @@ SSH keys to your account, so please use them before moving on!
you can check out [this website](https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process),
you can check out [this website](https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process),
which has more in-depth information than we provide here.
which has more in-depth information than we provide here.
* Generate the key
GitHub has excellent, platform-specific
instructions on how to [generate](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) SSH keys, but you can follow the instruction below:
!!! Note "Create your SSH key"
First check you do not have one already:
```
ls ~/.ssh/*.pub
```
If you have one, just open the `.pub` file and copy the content.
Otherwise type:
```
ssh-keygen -t ed25519 -C "your_email@example.com"
```
and type enter in the subsequent prompted questions.
Then read the content of the `.pub` file located in `~/.ssh/`
* Add the key to github
GitHub has excellent, platform-specific
instructions on how to [add](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account#adding-a-new-ssh-key-to-your-account)
SSH keys to your account, so please use them before moving on!
## Create a remote repository
## Create a remote repository
Log in to your GitHub account and press the *New* button:
Log in to your GitHub account and press the *New* button:
* We have not yet synced the local and remote repositories, though, we've simply
* We have not yet synced the local and remote repositories, though, we've simply
connected them. Let's sync them now:
connected them. Let's sync them now:
```bash
git push
```
!!! question "What happens?"
??? example "Click to show the solution"
You get the message `fatal: The current branch master has no upstream branch.` because git does not know to which branch to push the data.
We need to tell to the `push` command to push our local history of the `main` branch to the same
branch on the remote (`origin`).
```bash
```bash
git push origin main
git push origin main
```
```
The `push` command sends our local history of the `main` branch to the same
Our Git repository is now stored on GitHub!
branch on the remote (`origin`). Our Git repository is now stored on GitHub!
* Run `git status`. This should tell you that:
* Run `git status`. This should tell you that:
...
@@ -112,10 +150,18 @@ On branch main
...
@@ -112,10 +150,18 @@ On branch main
nothing to commit, working tree clean
nothing to commit, working tree clean
```
```
You always need to specify `git push origin main` by default, but you can
!!! Note
circumvent this by telling Git that you always want to push to
* You always need to specify `git push origin main` by default, but you can
`origin/main` when you're on your local `main` branch. To do this, use
circumvent this by telling Git that you always want to push to
the command `git branch --set-upstream-to origin/main`. **Try it out now**.
`origin/main` when you're on your local `main` branch. To do this, use
the command `git branch --set-upstream-to origin/main`.
* To avoid having to write git push -u origin new-branch every time you create and push a new branch, you can configure Git to automatically set up the upstream branch when pushing:
`git config --global push.autoSetupRemote always`
Configure Git to automatically set up the upstream branch when pushing using the name of the local branch:
```bash
git config --global push.autoSetupRemote always
```
* Now run `git-status` again. You should see that now git additionally tells you
* Now run `git-status` again. You should see that now git additionally tells you
that your local branch is up to date with the remote branch.
that your local branch is up to date with the remote branch.
...
@@ -138,14 +184,14 @@ see. Let's try it out!
...
@@ -138,14 +184,14 @@ see. Let's try it out!
```markdown
```markdown
# A Git tutorial
# A Git tutorial
This repository contains tutorial information related to the **NBIS/ELIXIR** course
This repository contains tutorial materials for the **Git course**, designed to help you learn and master *version control*.
*Tools for Reproducible Research*, specifically the session on using the `git`
software for version control.
`This can be code`
## Links
## Links
You can find the latest stable version of the Git tutorial for the course
You can find the latest stable version of the Git tutorial for the course