gitworkshop

Instructions and details for a git workshop

View on GitHub

Windows

On this training course we are going to use mostly Bash, but it will also work from PowerShell.

Installing git and bash

You can either follow this Video Tutorial or follow the instructions below:

  1. Download the Git for Windows installer.
  2. Run the installer and follow the steps below:
    • Click on “Next” four times (two times if you’ve previously installed Git). You don’t need to change anything in the Information, location, components, and start menu screens.
    • Select “Use the nano editor by default” and click on “Next”.
    • Keep “Git from the command line and also from 3rd-party software” selected and click on “Next”. If you forgot to do this programs that you need for the workshop will not work properly. If this happens rerun the installer and select the appropriate option.
    • Click on “Next”.
    • SSL: Ensure that “Use the native Windows Secure Channel library” is selected and click on “Next”.
    • Keep “Checkout Windows-style, commit Unix-style line endings” selected and click on “Next”.
    • Select “Use Windows’ default console window” and click on “Next”.
    • Ensure that “Enable file system caching” and “Enable Git Credential Manager” are selected and click on “Next”.
    • Click on “Install”.
    • Click on “Finish”.
  3. Check that the installation worked fine, open git bash
    • Does the terminal window say MINGW64 on the top?
    • Select a word on the terminal with the mouse, if you click with the right button of your mouse, does it paste it?

Python

On this online workshop we need to have a working version of python.

  1. Download the latest version of anaconda.
  2. Double click on the file downloaded.
  3. Welcome window - click “Next”
  4. License - read it and click “Agree”
  5. Installation type: Keep it with the recommended option (i.e., Just me) - click “Next”
  6. Install location: Keep it with the default (i.e., c:\Users\{username}\AppData\Local\Continuum\anaconda3) - click “Next” (If you change it, please avoid a path that contains blank spaces. If your “username” contains spaces, then change the path).
  7. Advanced installation options: Select both checkboxes
    • “Add anaconda to my PATH environment variable” and
    • “Register Anaconda as my default Python 3.7”
    • click “Install” (The first checkbox will show text in red. It’s OK)
  8. Thanks window: untick both checkboxes - click “Finish”

Git bash aware of anaconda

The following steps will allow to run anaconda’s python from within the git bash terminal

  1. Open a new git bash terminal
  2. Run the command: conda init bash, that will show a set of paths. The last one saying modified c:\Users\username\.bash_profile`
  3. Before closing that terminal, run the following:
    echo '. ${HOME}/.bash_profile' >> ~/.bashrc 
    

    Note that the quotes are single quotes ' and that there’s a . after the first quote.

  4. Open a new git bash terminal, it should say (base) on the first line.

Text editor

The installation of Git bash will provide you with nano.

  1. Open a git bash terminal
  2. Type the following command:
    nano
    

    Your terminal is now a text editor! If it looks like their website then you are good to go!

  3. To exit the editor and go back to the terminal type: ctrl+x

We will also use VS Code. Follow these instructions to get VS Code integrated with gitbash.

  1. Open the anaconda navigator
  2. Search for the VS Code button on the launcher, and click “Install”
  3. After installed, click “Launch” or search for it from the Windows start menu
  4. Let’s change the default shell:
    • Press: Shift + Ctrl + p to open the palette.
    • Type on the palette menu: “default shell”, press Enter
    • Choose “Git Bash” from the three available options
    • Now when you open a terminal (either by the terminal menu or by Shift + Ctrl + ') it should be a gitbash terminal.
  5. To open VS Code from the git bash you can call it as:
    code <filename>
    

Working with Python files?

If you are planning to use VS Code with python files, then follow these instructions

  1. It’s a good practice to use “open folder” when working with projects. Open a folder where you have (or can add) some python files.
  2. The python add-on should be installed already and in the bar below should say “Python (base: conda)”
  3. Clicking the play button on the top-right corner should run the python file.

Testing

Let’s make pytest the default testing framework to use:

  1. Create a python file (e.g., mycode.py) and write a simple function (myfunc)).
  2. Create a test file (e.g., test_mycode.py) and write a simple test (test_myfunc) that uses the function from the python file
  3. Open the palette: (Press: Shift + Ctrl + p) and type “Python configure tests”
  4. Select “Pytest”
  5. Select “. Root directory”

Now, at the bottom it should appear “Run Tests”, if you click and select All (from the palette), VS Code will run all the tests.

Debugging

Debugging should work also out of the box

Other extensions

For extra git functionality, we’ve suggest to install the “Git Graph” extension (from the top menu: View/Extensions, or the squares icon on the left bar).

Other options (advanced users only)

Using Windows Subsystem for Linux

Another option to benefit from the development Linux tooling is to install WSL. There’s a detailed set of instructions on how to run VS Code with that setup. To enable anaconda you would need to install it within the WSL.

Using a virtual machine

There’s a very nice virtual machine (VM) with all anaconda installed that you can download and use it. You need first to install Virtual Box. When you open the downloaded VM, VirtualBox will start to import it. Then you can run it. It will open a version of ubuntu which has anaconda installed. Few things to keep an eye for:

  1. The keyboard comes by default in Spanish (I don’t have anything to do with it!) - click in the bottom-left corner button, next to the time. You can change between US and ES. Clicking with the right button you can get a menu where you can add whichever layout you like (e.g., GB) and remove the others or set in the order you prefer.
  2. That machine is missing git… so you need to install it. Open a terminal and type:
    sudo apt-get update
    sudo apt-get install git
    
  3. The sudo password for that virtual machine is lubuntu.
  4. To add a shared folder between your local machine and the guest (the virtual machine):
    • turn off the VM,
    • open VirtualBox,
    • select the anaconda machine,
    • go to settings, and select “shared folders”. Choose the folder you want to share and give it a name. Don’t add a mounting point, they will appear under /media/sf_{folderName}/. Next time you open the anaconda VM the folder will also appear on the file browser (PCManFM icon on the Desktop).