Frequently Asked Questions

Introduction to version control

Command Line

FAQ: “How can I abort a command?”

Abort the command by typing Ctrl + C simultaneously.

FAQ: “I forgot to close the quotation marks of my commit message! What do I do?”

In this situation, you command line probably looks like one of these examples:

Output
echo "Hello World
>
>
>
Output
git commit -m "Add filename.txt
>
>
>

You can try one of the following solutions:

  1. Close the quotation marks by entering another ".
  2. Abort the command by typing Ctrl + C simultaneously and repeat it (now with quotation marks closed).
FAQ: What is the difference between Git Bash and PowerShell on Windows?

Git Bash and PowerShell are two different command-line shells that you can use on Windows. They differ in their origin, their syntax, and the commands and tools that they provide.

  • Git Bash is installed together with Git for Windows. It provides a Bash emulation based on MSYS2 and a set of common Unix command-line tools, such as ls, cd, grep, rm, and ssh. It uses Unix-style paths (for example, /c/Users/yourusername) and the Bash syntax that most commands in this book are written for.
  • PowerShell is Microsoft’s task automation and configuration management framework. It includes a command-line shell and a scripting language that is built on .NET. PowerShell uses cmdlets with a verb-noun naming scheme (for example, Get-ChildItem), an object-oriented pipeline, and Windows-style paths (for example, C:\Users\yourusername). Many Unix-style names such as ls or cd also work as aliases for cmdlets, but their output and behavior can differ from their Unix counterparts.

The Git program itself works in both shells, and Git commands such as git status or git commit are the same in both. The difference is the shell that interprets your input: Git Bash uses Bash syntax and Unix tools, while PowerShell uses PowerShell syntax and cmdlets. Some commands that work in Git Bash will therefore not work in PowerShell without modification, and vice versa. For example, the environment variable for your home folder is $HOME in Git Bash but $env:USERPROFILE in PowerShell.

Our recommendation: On Windows, use Git Bash for the examples in this book. The commands in this book are written for Bash or Zsh, and Git Bash provides the Unix tools and syntax that they rely on. If you prefer PowerShell, you can still use Git, but you may need to translate some commands and path specifications.

FAQ: What are the differences between Bash and Zsh?

Bash (Bourne Again SHell) and Zsh (Z shell) are both Unix shells. They are largely compatible, and the Git commands used in this book work in both of them.

The most important differences are:

  • Default shell: Bash is the default shell on most Linux distributions and on macOS up to Mojave. Zsh is the default shell on macOS Catalina and later.
  • Interactive features: Zsh offers more advanced features for interactive use, such as improved tab completion, spelling correction, powerful globbing, customizable prompts, and a large ecosystem of plugins and themes (for example, Oh My Zsh).
  • Scripting syntax: There are differences that matter when writing shell scripts, for example in array indexing (Bash arrays start at index 0, while Zsh arrays start at index 1 by default), word splitting, and globbing behavior. Bash and Zsh also use different startup files (for example, .bashrc and .bash_profile versus .zshrc and .zprofile).

For everyday Git usage, these differences rarely matter: the commands git status, git add, git commit, git switch, and so on are identical in Bash and Zsh. Our recommendation: Use the default shell of your operating system, or Git Bash on Windows, and do not worry about switching shells for this book.

Installation

Setup

First steps with Git

Git essentials

Branches

FAQ: How many branches is normal?

There is no fixed or “normal” number of branches. The right number depends on the size of your project, the number of people working on it, and your workflow. For a small research project, having a handful of active branches at any given time is typical. You do not need dozens of branches.

Some general guidelines:

  • Every repository has at least one branch: the default branch, usually called main or master.
  • A common pattern is to have the default branch plus one short-lived branch per task, such as a new feature, a bug fix, or a single analysis. Once the work is finished and merged, the branch is deleted.
  • In research projects, it can make sense to use one branch per analysis variant, manuscript revision, or experiment, so that you can compare and switch between them without affecting the main branch.
  • Large software projects may have additional long-lived branches, for example for releases or for maintaining older versions. This is optional and usually not necessary for small research projects.

Branches in Git are cheap: they are just pointers to commits, so creating a new branch does not copy your files. The real challenge is keeping them organized. To avoid clutter, follow the best practices for branches, name branches consistently, keep them focused on a single task, delete branches after merging, and do not keep stale branches around longer than necessary.

FAQ: How can I compare two analyses on separate branches?

If the two analyses are stored on two branches, you can compare them with Git’s git diff command.

First, make sure that both branches exist in your local repository (use git branch to list them). Then compare the branches, for example main and feature:

Code
git diff main..feature

This shows the differences between the two branch tips: what you would need to change in main to get the content of feature. The branch that you consider the “old” or “reference” version goes first, and the branch that you want to compare against it goes second.

Useful variants:

  • git diff main..feature --stat shows a summary of the changed files instead of the full diff.
  • git diff main..feature -- analysis/ restricts the comparison to a specific folder, for example the folder that contains your analysis scripts.
  • git diff main..feature -- analysis/script.R compares a single file.
  • git diff main...feature (with three dots) compares the point where the two branches diverged (the merge base) with the tip of feature. This shows only the changes that were made on feature since it branched off, which can be easier to read when main has also changed in the meantime.
  • git diff --word-diff main..feature highlights changed words instead of changed lines, which can be helpful for comparing text such as manuscripts.
  • git log --oneline --graph --all --decorate visualizes the commit history of both branches.

git diff only works for files that Git tracks and that it can display as text. If your analyses produce large binary files (for example, images or .docx files), Git cannot show a meaningful difference for them. In that case, check out each branch and compare the output files with a dedicated comparison tool, or use git difftool.

If you want to run or inspect both analyses at the same time without switching branches back and forth, you can use git worktree to check out a second branch into a separate folder:

Code
git worktree add ../analysis-feature feature

This creates a new folder ../analysis-feature that contains the files from the feature branch, while your current folder stays on its current branch. You can then run both analyses and compare their outputs directly.

Remotes: Introduction

FAQ: What are the differences between GitHub and GitLab?

GitHub and GitLab are both platforms for hosting Git repositories and collaborating on projects. They are not replacements for Git: Git is the version control system that runs on your computer, while GitHub and GitLab are remote hosting services that store Git repositories on the internet or on a server. The Git commands in this book work in the same way with both platforms.

The two platforms share many features, including repositories, issues, pull requests or merge requests, code review, wikis, releases, and continuous integration and delivery (CI/CD). Some differences are:

  • Terminology: GitHub calls a proposed change a pull request, while GitLab calls it a merge request. On GitHub, users and repositories can be organized in organizations. On GitLab, the equivalent is a group.
  • CI/CD: GitHub uses GitHub Actions, configured in .github/workflows/. GitLab uses GitLab CI/CD, configured in a .gitlab-ci.yml file.
  • Hosting: GitHub is primarily used as a cloud service at github.com. GitLab is also available as a cloud service at gitlab.com, but its Community Edition can additionally be installed and operated on your own server. This is why many universities and research institutions, including the University of Hamburg and the Max Planck Institute for Human Development, run their own GitLab instances.
  • Popularity and ecosystem: GitHub is the largest platform for open-source projects and has a very large ecosystem of integrations. GitLab is particularly common in organizations and research institutions that value self-hosting and an integrated DevOps platform.
  • Free plans: Both platforms offer free plans, but the included features and limits differ and can change over time. Check the current GitHub pricing and GitLab pricing pages before choosing a plan.

Which one should you use? In most cases, use the platform that your institution, your research group, or your collaborators use. If you are free to choose, GitHub is a good default because of its popularity and large community, while GitLab is a strong choice if you need to host repositories on your own infrastructure.

FAQ: I can’t connect using my SSH key?

As a first step, try going through the process again, whilst paying special attention to doing every step carefully. Oftentimes, there is some confusion when copying the SSH key to the clipboard or when entering a new passphrase, as there’s no visible feedback. After entering the command for copying the SSH key, you can usually trust that it is in your clipboard and move on to the next step. Similarly, be cautious what you are typing in as a passphrase, as you can’t see what you are entering. If you don’t want a passphrase, simply click enter twice when asked to set one up, leaving the passphrase empty.
Another issue could be that you have a pre-existing SSH key set up. You will get a warning about this and can simply use this pre-existing one to connect to your remote server of choice.

If none of these were the source of your issues, check out the GitHub SSH key troubleshooting documentation or the GitLab troubleshooting SSH site.

FAQ: My PAT is not shown when I enter it into the terminal?

When authenticating with GitHub on macOS, you may notice that the password doesn’t show up in the command line as you type it. This is normal behavior to ensure security. You can still enter your password (or delete what you typed) even though it doesn’t appear on the screen. You can also copy and paste text, for example your PAT from GitHub. When authenticating on Windows, a new window might pop up in which you can enter your PAT.

GitHub: Intro

GitHub: Advanced

Tags and Releases

Issues

Graphical User Interfaces

Stashing and Co.