Skip to content

Github basics

alex-ebi edited this page Jun 27, 2023 · 13 revisions

If you are new to github, you might have problems on learning how to use git. To understand the basics, you should be a bit learning by doing (the best kind of learning imo). For that, make your own github project following this Tutorial. If you have a lot of time and interest, you can master the other aspects of github at this Quickstart site. Another neat introduction on how to make a proper repository is Scientific Python Cookiecutter

Important commands

If you don't have a lot of time, here are some essential commands, you will need to work with the EDIBLES repository.

Clone the EDIBLES repository

git clone https://github.com/jancami/edibles.git

With this command you download the EDIBLES repository. Essentially you get a full copy of the repository.

Checkout an online branch.

git switch -c branch_name --track origin/branch_name

The "-c" indicates to create a new local branch, which tracks the same named online branch. You need this command to switch to another remote branch. By default (when you cloned the repository), you are on the master branch. The master branch should always work and is usually protected from being altered by anyone else than the project owner.

Reset a branch

It might happen that you found a bug and a fix was pushed on the github. You can overwrite your local branch by first resetting it to the last commit:

git reset --hard HEAD

, and then pulling the latest commit:

git pull

Generate an ssh key

ssh-keygen -t ed25519 -C "<comment>"

To push your local project, it is best to use an ssh key, so github know it can trust your computer. The key is saved by default in "~/.ssh/id_ed25519.pub". You have to copy the key into the list of trusted keys of your github account (In your account settings under "SSH and GPG keys").