Moved around git stuff

This commit is contained in:
Tom van Woudenberg 2024-03-11 15:40:31 +01:00
parent a9d5cb7644
commit a7a90979bf
15 changed files with 171 additions and 199 deletions

View file

@ -8,23 +8,20 @@ parts:
sections:
- file: installation-and-setup/extension
- file: installation-and-setup/git-setup
- file: installation-and-setup/git-hub-desktop
- file: installation-and-setup/git-setup_local
sections:
- file: installation-and-setup/git-clone
- file: installation-and-setup/git-branch
- file: installation-and-setup/git-stage-commit-push
- file: installation-and-setup/git-merge
- file: installation-and-setup/anaconda
- file: installation-and-setup/add_conda_to_path
- file: installation-and-setup/working-directory
- file: installation-and-setup/environments
- file: installation-and-setup/vscode-setup
- file: installation-and-setup/jupyter-book-setup
- file: workflows/overview
sections:
- file: workflows/git-basic
sections:
- file: workflows/git-clone
- file: workflows/git-branch
- file: workflows/git-stage-commit-push
- file: workflows/git-merge
- file: workflows/git-advanced
sections:
- file: workflows/git-merge-conflict
sections:
- file: workflows/gitlab
- file: workflows/github
- caption: Features

View file

@ -0,0 +1,51 @@
# Getting Anaconda to work in terminal
(vscode-setup-bash)=
````{tab} Windows - Git Bash (preferred)
There are two things to do before you can use conda in your Git Bash CLI (possibly in VS Code): 1) adding Anaconda to your PATH variables (as user, *not* as system/admin), and 2) setting up Anaconda to run on Git Bash.
1. update the `PATH` variables:
* search for 'env' in the windows search to find the settings page. Anaconda doesn't recommend adding them to the system `PATH`, therefore when searching for the setting with the Windows search, so be careful to open **"edit environment variables for your account"**; do **not** "edit the system environment variables".
* Identify the box for adding variables for a specific user (the top box), not the system.
* select the line with 'Path' and click edit
* Add the `Anaconda3` and `Anaconda3/Scripts` directories to `PATH`.
You will know if this worked because the `conda` commands below will not produce an error. You can also check by opening a Git Bash terminal and listing your Anaconda environments with `conda env list`.
2. To setup Anaconda, open git bash and run the collowing commands (note, the first two commands to create `myenv` can be skipped if you already have an Anaconda environment; e.g., default is `base`):
* `conda create -n myenv python`
* `conda install -n myenv numpy`
* run `conda init bash` to link conda to Git Bash
* restart shell (type `exit` to close)
* run `conda activate myenv`
* restart shell
Check if it worked by opening a notebook in an aribtrary `DIR` using the command `jupyter lab --notebook-dir DIR`.
````
````{tab} MacOS
Usually, Anaconda works by default in the MacOS terminal. To check if it works for you type `conda` in the termal and execute. If you get help page for `conda`, you're all set. In VS code, open a new terminal by clicking **View > Terminal** in the top menu bar.
If you don't get a help page but something like:
zsh: command not found: conda
then do the following:
1. Find out where Anaconda is installed on your system. If you left everything as default during the installation, Anaconda is installed in `/Users/<username>/anaconda3` if you used the install script, or in `/Users/<username>/opt` if you used the graphical interface to install Anaconda.
2. Execute the following line:
source <anaconda-installation-dir>/bin/activate
3. Then:
conda init zsh
4. Restart the terminal / VS Code then test by executing `conda` again. This time, it should give you the help page. You now have access to you Anaconda environments in your command line.
````
````{tab} Windows - Powershell
```{note}
This is not the preferred installation method: Powershell has a different set of terminal commands that are not Unix-based, whereas Git Bash does. Since the vast majority of coding information and examples on the internet related to Jupyter and other open source projects uses Unix-based commands, we strongly recommend you always run Git Bash for your work in the terminal.
```
````

View file

@ -1,7 +0,0 @@
# GitHub Desktop
By now you should have an idea on the purpose of git and GitLab. GitHub is a competitor company to GitLab. It provides very similar services, but they are often called different names, or have slightly different features. GitHub provides a free software that is very useful: GitHub Desktop!
While GitLab is a cloud-based version control system built around git, GitHub Desktop makes it possible to manage our git repositories locally on our computers, even though they are stored on GitLab. this is very useful for working with the jupyter-book more extensively and work on interactive features.

View file

@ -1,4 +1,6 @@
# What is Git and how do I set it up
# What is Git and GitLab?
In this section you will learn how to perform basic Git actions in the online interface of GitLab.
## What is Git?
@ -8,75 +10,10 @@ Git is a version control system (VCS), used by a wide variety of engineers and s
GitLab is a cloud-based version control system built around git. It provides a lot more features such as Issues, Merge Requests, CI/CD pipelines, etc. TU Delft has a license to use GitLab on our own local webservers—this means that all of the files are stored digitally on the TU Delft campus, rather than some unkown webserver that could be physically located in an unsafe location. This is also why we have our “own” GitLab located at gitlab.tudelft.nl, rather than the “normal” GitLab at gitlab.com.
## Installing Git
## Terminology
This is a (non-exhaustive) list of terminology that will be used in GitLab.
First, we need to install Git itself.
````{tab} Windows
1. Go to [this webpage](https://git-scm.com/download/win) and download the correct version of Git for your system.
2. Execute the installer and go through it. You can leave all options to the default values, **but make sure the option "Git from the command line and also from 3rd-party software" is selected**. Without this option, we won't be able to use Git from VS Code.
3. Once the installation is finished, check if everything works. Open the start menu, then type `git`. From the search results, open the application `Git Bash`. This will open a terminal window, in which you can execute commands. Type in the command `git`, and execute it by pressing enter. If Git is installed correctly, you should see some sort of help page. If it outputs an error, then something may went wrong with the installation (you may have selected a wrong option).
````
````{tab} MacOS
Open up a terminal window (*Command + Space*, type in `terminal`). Then, type the command `git`. If Git has been installed already, it will output some help. If Git has not been installed, you will get a pop-up that looks something like this:
```{figure} ../images/install-Xcode-CLT.png
```
Click on `install`. The installation may take a couple of minutes. Once it's finished, check if everything has been installed correctly by exectuting `git` again.
````
## Setting up SSH-keys
When we want to visit repositories on GitLab, we need to log in. The same holds if we want to interact with these repositories with Git from VS Code. This means that everytime we make a commit, pull, et cetera, we need to provide our password, which becomes very tedious. Alternatively, we can provide GitLab with an SSH-key of our sytem, so that GitLab knows it is indeed us that are making the changes to the repository, removing the need to provide a password.
1. Open up a terminal window (Git Bash on Windows). Next, type (or copy and paste) the following command:
ssh-keygen -t ed25519 -C "GitLab"
2. You will get output that looks something like this:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/<user>/.ssh/id_ed25519):
Press enter to use the default path (the one between parenthesis). Keep note of this path, as we will need to visit it later on.
3. You will now be asked to enter a passphrase. You can give one, but you will be asked for it everytime you make a commit, so it's better to leave this field emtpy and use this key only for GitLab. After the command is done executing, it will generate two files: `id_ed25519` and `id_ed25519.pub`. The `.pub` file is the public part of the SSH-Key which we need.
4. Go to [GitLab](https://gitlab.tudelft.nl) and log in using your NetID. Click on your profile icon on the top-right of the page, then go to Preferences. In the menu on the left, go to SSH-Keys. You are now greeted with a screen that looks like this:
```{figure} ../images/gitlab-ssh-screen.png
```
5. Navigate to the `id_ed25519.pub` file that we generated in step 2. Open the file with a text editor (Notepad on Windows, textEdit on Mac). Copy its contents and paste it in the 'Key' field of SSH-Keys menu. Give the key a Title and click 'Add key'.
```{note}
On MacOS, the `.ssh/` folder is hidden by default, so you won't be able to find it in finder. To show hidden files and folders, press **Command + Shift + .**
```
6. Now test the connection. Go to the terminal (Git Bash on windows) and type:
ssh -vT git@gitlab.tudelft.nl
You should get a huge output, but somewhere at the end of that output it should say something like:
Welcome to GitLab, <netid>!
## Updating the local Git environment
The final step is to provide a username and email address to Git, so our commits can be identified. To do this, in the terminal (Git Bash on Windows) type in the following command for the username:
git config --global user.name "<first name> <last name>"
And type the following command to set the email address:
git config --global user.email "<your TU Delft email>"
## Configuring Git Bash
Git Bash is a shell (also referred to as "the terminal") that is automatically installed with git. It provides Unix-like commands on a Windows OS, and is recommended for working with open source projects like Jupyter (for example `pip install`, building Jupyter books, using Git Bash in VS Code, etc). To do this, `conda` needs to be setup properly; this is described in the {ref}`instructions for setting up VS Code <vscode-setup-bash>`.
## More on GitLab
To get to know more about working in GitLab and getting familiar with its features, click [here](/jupyter-book-manual/book/workflows/overview.md) or watch this [video](https://www.youtube.com/watch?v=1SBtM3znviU&t=1s)!
- Repository: a collection of files and folders, along with a history of their changes and who made them.
- Commit: a snapshot of the current state of the repository.
- Branch: a development line.
- Pushing: uploading new commits to the remote repository.

View file

@ -0,0 +1,96 @@
# How do I use Git locally?
In this section you will learn how to perform basic Git actions in VS Code / GitHub Desktop. Courses on Git usually make use of the command line interface to do these actions, but this introduces a steep learning curve. Instead, using Git from VS Code / GitHub Desktop is much more visual (i.e., more "clicky"), and therefore easier to use for those inexperienced with the command line.
## GitHub Desktop
GitHub is a competitor company to GitLab. It provides very similar services, but they are often called different names, or have slightly different features. GitHub provides a free software that is very useful: GitHub Desktop!
While GitLab is a cloud-based version control system built around git, GitHub Desktop makes it possible to manage our git repositories locally on our computers, even though they are stored on GitLab. This is very useful for working with the jupyter-book more extensively and work on interactive features. GitHub Desktop provides an alternative to Git in VS Code, and will be described on a later stage.
## Terminology
This is a (non-exhaustive) list of terminology that will be used in Git for local use.
- Repository: a collection of files and folders, along with a history of their changes and who made them.
- Commit: a snapshot of the current state of the repository.
- Staging: preparation of files to be committed. During staging, we propose files to be committed.
- Branch: a development line.
- Local: on your own computer.
- Remote: on someone elses computer.
- Pushing: uploading new commits to the remote repository.
- Pulling: downloading new commits from the remote repository to your local repository.
- Tracked (files): files that Git knows about and keeps track of their history.
- Untracked (files): files that Git does not yet know about.
## Installing Git
First, we need to install Git itself.
````{tab} Windows
1. Go to [this webpage](https://git-scm.com/download/win) and download the correct version of Git for your system.
2. Execute the installer and go through it. You can leave all options to the default values, **but make sure the option "Git from the command line and also from 3rd-party software" is selected**. Without this option, we won't be able to use Git from VS Code.
3. Once the installation is finished, check if everything works. Open the start menu, then type `git`. From the search results, open the application `Git Bash`. This will open a terminal window, in which you can execute commands. Type in the command `git`, and execute it by pressing enter. If Git is installed correctly, you should see some sort of help page. If it outputs an error, then something may went wrong with the installation (you may have selected a wrong option).
````
````{tab} MacOS
Open up a terminal window (*Command + Space*, type in `terminal`). Then, type the command `git`. If Git has been installed already, it will output some help. If Git has not been installed, you will get a pop-up that looks something like this:
```{figure} ../images/install-Xcode-CLT.png
```
Click on `install`. The installation may take a couple of minutes. Once it's finished, check if everything has been installed correctly by exectuting `git` again.
````
## Setting up SSH-keys
When we want to visit repositories on GitLab, we need to log in. The same holds if we want to interact with these repositories with Git from VS Code. This means that everytime we make a commit, pull, et cetera, we need to provide our password, which becomes very tedious. Alternatively, we can provide GitLab with an SSH-key of our sytem, so that GitLab knows it is indeed us that are making the changes to the repository, removing the need to provide a password.
1. Open up a terminal window (Git Bash on Windows). Next, type (or copy and paste) the following command:
ssh-keygen -t ed25519 -C "GitLab"
2. You will get output that looks something like this:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/<user>/.ssh/id_ed25519):
Press enter to use the default path (the one between parenthesis). Keep note of this path, as we will need to visit it later on.
3. You will now be asked to enter a passphrase. You can give one, but you will be asked for it everytime you make a commit, so it's better to leave this field emtpy and use this key only for GitLab. After the command is done executing, it will generate two files: `id_ed25519` and `id_ed25519.pub`. The `.pub` file is the public part of the SSH-Key which we need.
4. Go to [GitLab](https://gitlab.tudelft.nl) and log in using your NetID. Click on your profile icon on the top-right of the page, then go to Preferences. In the menu on the left, go to SSH-Keys. You are now greeted with a screen that looks like this:
```{figure} ../images/gitlab-ssh-screen.png
```
5. Navigate to the `id_ed25519.pub` file that we generated in step 2. Open the file with a text editor (Notepad on Windows, textEdit on Mac). Copy its contents and paste it in the 'Key' field of SSH-Keys menu. Give the key a Title and click 'Add key'.
```{note}
On MacOS, the `.ssh/` folder is hidden by default, so you won't be able to find it in finder. To show hidden files and folders, press **Command + Shift + .**
```
6. Now test the connection. Go to the terminal (Git Bash on windows) and type:
ssh -vT git@gitlab.tudelft.nl
You should get a huge output, but somewhere at the end of that output it should say something like:
Welcome to GitLab, <netid>!
## Updating the local Git environment
The final step is to provide a username and email address to Git, so our commits can be identified. To do this, in the terminal (Git Bash on Windows) type in the following command for the username:
git config --global user.name "<first name> <last name>"
And type the following command to set the email address:
git config --global user.email "<your TU Delft email>"
## Configuring Git Bash
Git Bash is a shell (also referred to as "the terminal") that is automatically installed with git. It provides Unix-like commands on a Windows OS, and is recommended for working with open source projects like Jupyter (for example `pip install`, building Jupyter books, using Git Bash in VS Code, etc). To do this, `conda` needs to be setup properly; this is described in the {ref}`Getting Anaconda to work in terminal <vscode-setup-bash>`.
## More on GitLab
To get to know more about working in GitLab and getting familiar with its features, click [here](/jupyter-book-manual/book/workflows/overview.md) or watch this [video](https://www.youtube.com/watch?v=1SBtM3znviU&t=1s)!

View file

@ -16,10 +16,10 @@ Different types of users will interact with the website or the Jupyter Books dif
Now that the types of users have been explained, you might have an idea which type corresponds to you! <br>
The following table will link the relevant installation and setup steps for you.
||<div style="width:120px">User Types</div>|<div style="width:400px">Relevant Sections</div>|<div style="width:150px">Installation</div>|
|:---:|:---:|:---|:---|
|<img src="figures/type 1.jpg" alt="Example Image" width="300"/>| Type 1<br>Type 2 | No software needed!<br>Just open your interactive book and navigate to the extension | [Extension Tutorial](extension.md) |
| | Type 3 | Understanding Git & GitLab | [Git & GitLab](git-setup.md) |
| | Type 4 | Understanding Git & GitLab<br>Local and remote repositeries with GitHub Desktop<br>Edit using VS Code<br>Anaconda<br>Working with directories<br>Python Environments<br>Python package: Jupyter book | [Git & GitLab](git-setup.md)<br>[GitHub Desktop](git-hub-desktop.md)<br>[VS Code](vscode-setup.md)<br>[Anaconda](anaconda.md)<br>[Working directories](working-directory.md)<br>[Environments](environments.md)<br>[Jupyter Book](jupyter-book-setup) |
|<img src="figures/type 5.jpg" alt="Example Image" width="300"/>| Type 5 | All sections of user type 4 are also relevant for user type 5.<br>With the addition of using extensions to create interactive features! |[Features](../features/overview.md) |
|<div style="width:120px">User Types</div>|<div style="width:400px">Relevant Sections</div>|<div style="width:150px">Installation</div>|
|:---:|:---|:---|
| Type 1<br>Type 2 | No software needed!<br>Just open your interactive book and navigate to the extension | [Extension Tutorial](extension.md) |
| Type 3 | Understanding Git & GitLab | [Git & GitLab](git-setup.md) |
| Type 4 | Understanding Git & GitLab<br>Local and remote repositeries with VS Code / GitHub Desktop<br>Edit using VS Code<br>Anaconda<br>Using Anaconda in terminal<br>Working with directories<br>Python Environments<br>Python package: Jupyter book | [Git & GitLab](git-setup.md)<br>[How do I use git locally?](git-setup_local.md)[VS Code](vscode-setup.md)<br>[Anaconda](anaconda.md)<br>[Anaconda in terminal](add_conda_to_path.md)<br>[Working directories](working-directory.md)<br>[Environments](environments.md)<br>[Jupyter Book](jupyter-book-setup) |
| Type 5 | All sections of user type 4 are also relevant for user type 5.<br>With the addition of using extensions to create interactive features! |[Features](../features/overview.md) |

View file

@ -21,73 +21,4 @@ By default, Powershell is the default terminal used in VS Code. However, Git Bas
* Start type "terminal default" and you will soon see and be able to select the setting "Terminal: Select Default Profile" (hit `Enter`)
* select Git Bash and hit "Enter" again to set as default
When creating a new terminal via the menu bar you should now automatically start with a Git Bash terminal. Note that if a Powershell terminal still opens by default, you can always create a new terminal and manually select Git Bash.
## Getting Anaconda to work in the VS Code terminal
(vscode-setup-bash)=
````{tab} Windows - Git Bash (preferred)
There are two things to do before you can use conda in VS Code: 1) adding Anaconda to your PATH variables (as user, *not* as system/admin), and 2) setting up Anaconda to run on Git Bash.
1. update the `PATH` variables:
* search for 'env' in the windows search to find the settings page. Anaconda doesn't recommend adding them to the system `PATH`, therefore when searching for the setting with the Windows search, so be careful to open **"edit environment variables for your account"**; do **not** "edit the system environment variables".
* Identify the box for adding variables for a specific user (the top box), not the system.
* select the line with 'Path' and click edit
* Add the `Anaconda3` and `Anaconda3/Scripts` directories to `PATH`.
You will know if this worked because the `conda` commands below will not produce an error. You can also check by opening a Git Bash terminal and listing your Anaconda environments with `conda env list`.
2. To setup Anaconda, open git bash and run the collowing commands (note, the first two commands to create `myenv` can be skipped if you already have an Anaconda environment; e.g., default is `base`):
* `conda create -n myenv python`
* `conda install -n myenv numpy`
* run `conda init bash` to link conda to Git Bash
* restart shell (type `exit` to close)
* run `conda activate myenv`
* restart shell
Check if it worked by opening a notebook in an aribtrary `DIR` using the command `jupyter lab --notebook-dir DIR`.
````
````{tab} MacOS
Usually, Anaconda works by default in the MacOS terminal. To check if it works for you, open a new terminal in VS Code by going clicking **View > Terminal** in the top menu bar. In the terminal window that appears, type `conda` and execute. If you get help page for `conda`, you're all set. If instead you get something like:
zsh: command not found: conda
then do the following:
1. Find out where Anaconda is installed on your system. If you left everything as default during the installation, Anaconda is installed in `/Users/<username>/anaconda3` if you used the install script, or in `/Users/<username>/opt` if you used the graphical interface to install Anaconda.
2. Execute the following line:
source <anaconda-installation-dir>/bin/activate
3. Then:
conda init zsh
4. Restart VS Code, then test by executing `conda` again. This time, it should give you the help page. You now have access to you Anaconda environments in the VS Code terminal.
````
````{tab} Windows - Powershell
```{note}
This is not the preferred installation method: Powershell has a different set of terminal commands that are not Unix-based, whereas Git Bash does. Since the vast majority of coding information and examples on the internet related to Jupyter and other open source projects uses Unix-based commands, we strongly recommend you always run Git Bash for your work in the terminal.
```
On Windows, Anaconda usually does not work in the integrated VS Code terminal (Powershell). To check if it works for you, open a new terminal in VS Code by going clicking **View > Terminal** in the top menu bar. In the terminal window that appears, type `conda` and execute. If you get help page for `conda`, you're all set. If instead you get something like:
conda : the term 'conda' is not recognized ...
then do the following steps:
1. Open Anaconda prompt **as administrator**.
2. Execute the following command:
conda init --all
3. Close the Anaconda prompt. Then, open a Powershell window **as administrator** (go to the Start menu, type Powershell, then open Windows Powershell as administrator).
4. In the Powershell window, execute the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
5. The command will ask you for some permissions. To do so, type `A`, then press enter.
6. Restart VS Code, then test by executing `conda` again. This time, it should give you the help page. You now have access to you Anaconda environments in the VS Code terminal.
````
When creating a new terminal via the menu bar you should now automatically start with a Git Bash terminal. Note that if a Powershell terminal still opens by default, you can always create a new terminal and manually select Git Bash.

View file

@ -1,4 +0,0 @@
(git-advanced)=
# Advanced Git topics
Under construction.

View file

@ -1,23 +0,0 @@
# Working with Git in VS Code
In this section you will learn how to perform basic Git actions in VS Code. Courses on Git usually make use of the command line interface to do these actions, but this introduces a steep learning curve. Instead, using Git from VS Code is much more visual (i.e., more "clicky"), and therefore easier to use for those inexperienced with the command line.
## What is Git?
Git is a version control system (VCS). In short, a VCS is a tool that helps you keep track of changes to you codebase (e.g., a Jupyter Book project!) over time. It allows you to keep track of the history of changes made to your code, work collaboratively with others, and revert to a previous version of the code if needed.
## What is GitLab?
GitLab is platform that hosts Git repositories, which can also be accessed through a web interface. Essentially, GitLab hosts the main repository that the members of a project interact with. Additionally, GitLab has plenty of other useful features such as issue tracking and code review. A selection of these features that are particularly useful for us as Jupyter Book developers will be highlighted in a {ref}`later section <gitlab>.
## Terminology
This is a (non-exhaustive) list of terminology that will be used throughout this section:
- Repository: a collection of files and folders, along with a history of their changes and who made them.
- Commit: a snapshot of the current state of the repository.
- Staging: preparation of files to be committed. During staging, we propose files to be committed.
- Branch: a development line.
- Local: on your own computer.
- Remote: on someone elses computer.
- Pushing: uploading new commits to the remote repository.
- Pulling: downloading new commits from the remote repository to your local repository.
- Tracked (files): files that Git knows about and keeps track of their history.
- Untracked (files): files that Git does not yet know about.

View file

@ -1,4 +0,0 @@
(merge-conflicts)=
# Merge conflicts
Under construction.

View file

@ -1,2 +0,0 @@
(gitlab)=
# Useful GitLab features