Output
echo "Hello World
>
>
>Abort the command by typing Ctrl + C simultaneously.
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:
".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.
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.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.
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:
.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.
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:
main or master.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.
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..featureThis 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 featureThis 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.
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:
.github/workflows/. GitLab uses GitLab CI/CD, configured in a .gitlab-ci.yml file.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.
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.
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.