Skip to content
Sven Gastauer edited this page Dec 10, 2024 · 4 revisions

ICES WGFAST Github & Python Workshop

Introduction

Git and Github

Hopefully we can largely steal or refer to Erin's intro....

In simple terms, Git tracks different verisons of files. It is commonly used to collaborate on code for software development. Git started off in 2005 as a 'simple' version control tool without and smart tools but has since evolved to become a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Importants terms

  • repository
  • clone
  • fork
  • branch
  • code
  • issues
  • Pull, Push and Commit
    ...

Git vs Github

Git is a version control system. Github is a cloud based hosting service, that lets you manage Git repositories.

Alternatives

While Git and Github are by far the most popular collaborative version colntrol tools, there are alternatives.
The most prominent Git alternative is mercurial Notable GitHub alternatives include (BitBucket)[https://bitbucket.org/], Gitea and GitLab. They both have similar tools available as Github but currently Github is the most popular and easiest to use platform. If you intend to self host a verison control site, Gitlab or Gitea could be a good alternative. We will focus solely on the use og Git and Github in this document.

Using Git and Github

Git command line

Install Git for (Mac)[https://git-scm.com/download/mac], (Linux)[https://git-scm.com/download/linux], (Windows)[https://git-scm.com/download/win]

Github desktop

The easiest way to use Github is to interact with repositories through a Desktop Client. The most commonly used Github client, is the official Github Dektop:
The latest veriosn of Github Desktop for Mac and Windows can be downloaded here[https://github.com/apps/desktop]
Popular client alternatives to Github Desktop include:

Basic Git

  • Fetch
  • Pull
  • Push
  • Commit

Install latest package version

pip install .

Python

conda

What is conda

Installing miniconda

Mac

Linux

  1. Download and rename the latest verison of Miniconda:
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
    Silently install miniconda:
    bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
    Remove the installer:
    rm ~/miniconda3/miniconda.sh
    Close and reopen the terminal and run:
    source ~/miniconda3/bin/activate
    To initialise conda on on all shells use:
    conda init --all

Windows

Install using Installer

Download the installer from the anaconda website
Install for current user, without automatically setting the Windows env Install Miniconda without setting the Path Environment
After the Miniconda setup finishes, we can't call conda from the command line until we have added it to our system environment.

Setting Path Environment
  1. Open the Start Menu and search for 'Environment Variables'. You will likely have to enter your admin credentials.
  2. Click on 'Edit the system environment variables'.
  3. In the System Properties window, click on 'Environment Variables'
Select Environmental Variables 4. In the Environment Variables window, under 'System variables', find and select 'Path', then click on 'Edit'. Edit Environmental Variables
  1. Add 'New' and select folder where Miniconda was installed:
    For conda, pip, etc.: C:\Users\<YOURUSERNAME>\AppData\Local\miniconda3\Scripts
    For Python: C:\Users\<YOURUSERNAME>\AppData\Local\miniconda3\

Press OK in all open Windows.

This should have made Python and conda accessible from the Anaconda Prompt. To test this, open a new Anaconda Prompt window:
Start Menu -> Anaconda (miniconda3) -> Anaconda Prompt.
Open Anaconda Prompt

Check miniconda and Python install

Open Anaconda prompt (or any terminal on Linux and Mac).

Check the verison of conda: conda info
Check which Python version is installed: python -V

Basic conda commands

Command Result
conda update conda Update conda to latest version
conda install PACKAGENAME
Example: conda install jupyter installs jupyter
Install a package included in Anaconda
conda update PACKAGENAME
Example: conda update jupyter updates the jupyter package
Update an installed package

Virtual environments

What is a virtual environment and why use it?

Creating a virtual conda environment
To create a new conda environment, we use the conda createcommand followed by --name envname where envname is the name of the environment tha tyou want to create.
The name of the environment can be followed by the python version to be installed and packages that should be included in the environment. For example we can create an environment called myen with python version 3.11 installed as follows:
conda create --name myenv python=3.11
if we wanted to include jupyter and echopype we would use: conda create --name myenv python=3.11 jupyter echopype