Summary and Setup
This is a new lesson built with The Carpentries Workbench.
This workshop is hands-on. You will type every command yourself, so please work through this page before the first session. It takes about 30 minutes, longer if you need to install things.
If you get stuck, email us and we will help you before the day. You will also have time at the start of the first session, but we’d rather spend it on git.
Is this workshop for you?
This is a follow-up to a beginner course and goes quicker. Read through these statements. You should be able to say yes to most of them.
Not sure about a few of them? That’s fine. Pick up the ones you missed in the Software Carpentry git lesson, which takes a couple of hours, and then come back.
Already comfortable with all of that, and with some rebasing? You’re welcome too. You will still pick up new tricks, and we like having experienced people in the room.
You do not need to have used git rebase
before. Most people haven’t, and that is what we will learn.
What you need
Tick these off as you go.
1. Git
Install Git for Windows. It comes with Git Bash, which is the terminal we will use. Leave the default options selected, except: if it asks about the default editor, choose Visual Studio Code (once you have installed it, below).
Open Terminal and run git --version. If git isn’t
installed, macOS offers to install the command line developer tools. Say
yes. Or, if you use Homebrew: brew install git.
Install it with your package manager, for example
sudo apt install git.
2. Visual Studio Code
We will use VS Code as our editor, our terminal and for a graphical view of git.
- Windows: re-run the VS Code installer and make sure Add to PATH is ticked. Then open a new terminal.
-
macOS: open VS Code, press
Cmd+Shift+P, type “shell command”, and choose Shell Command: Install ‘code’ command in PATH. Then open a new terminal. -
Linux: this is normally set up by the installer. If
not, reinstall from the
.deb/.rpm.
3. Python
peakfinder, the project we’ll work on, is a small Python
package that finds peaks in spectra. You don’t need to be a Python
expert, and we won’t be writing anything clever.
(Some systems call it python3.) If you don’t have it, we
recommend uv,
which installs Python for you and is what we use. Conda works as
well.
4. A GitHub account
-
- the GitHub CLI: install it,
then run
gh auth loginand follow the prompts (easiest), or - an SSH key, or
- a personal access token used as your password.
- the GitHub CLI: install it,
then run
You will test this in step 6.
5. Configure git
Run these commands once. They are settings that make the commands we use in the workshop work smoothly. We’ll explain what each does in the workshop itself. They are preferences, not rules: many people use git’s defaults, so you don’t need to keep them afterwards, though you may find you want to.
BASH
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global pull.rebase true
git config --global rebase.autoSquash true
git config --global push.autoSetupRemote true
Use the same email address as your GitHub account (or your GitHub no-reply address).
The core.editor line matters. Without it git opens a
terminal editor called vim, which is hard to leave if
you’ve never used it. If that ever happens, type :q! and
press Enter.
6. Get the project
-
Important: on the “Create a new fork” page, make sure “Copy the
mainbranch only” is UNTICKED. It is ticked by default. We need the other branches (and the tags) for the exercises.
OUTPUT
v0.1.0
v0.2.0
If you only see origin/main, your fork copied just one
branch. The quickest fix is to delete the fork (Settings >
Delete this repository, at the bottom) and make it again with
the box unticked.
OUTPUT
============================= test session starts ==============================
...
============================== 6 passed in 0.8s ===============================
If no window appears (for example you are on a remote machine) save the plot instead, and open the image file in VS Code:
It should say Everything up-to-date. If it asks for a
password, or says authentication failed, go back to step 4.
Check you’re ready
You should be able to say yes to all of these:
Troubleshooting
My fork only has the main branch. You
left “Copy the main branch only” ticked when forking.
Delete the fork and make it again.
I’m stuck in a strange editor in the terminal (vim).
Press Esc, then type :q! and press Enter. Then
set core.editor as in step 5.
code isn’t found, or git doesn’t wait for VS
Code. See step 2. The --wait in
core.editor is what makes git wait until you close the
tab.
pytest says
ModuleNotFoundError. Your virtual environment
probably isn’t active. Run the source .venv/bin/activate
line again. You should see (.venv) at the start of your
terminal prompt.
My laptop is locked down and I can’t install things. Tell us in advance. We are working on an alternative, so you can use a hosted environment instead.