Setting up Git#
Is Git available?#
Check if git
is available on your machine by running
git --version
If git is not available you can follow instructions here to install git in your machine.
Basic configurations#
When we use Git on a new computer for the first time, we need to configure a few things. Below are a few examples of configurations we will set as we get started with Git:
our name and email address,
to colorize our output,
what our preferred text editor is,
and that we want to use these settings globally (i.e. for every project)
User info#
On a command line, Git commands are written as git verb
,
where verb
is what we actually want to do. So here is how
Jane sets up her new laptop:
git config --global user.name "Jane Smith"
git config --global user.email "jane.smith@university.ac.uk"
Note
You need to do this only once if you pass the --global
option. If you want to override this with a different name or email address for specific projects, you can run the command without the --global
option when you’re in that project.
Please use your own name and email address instead of Jane’s. Later on in this workshop, we’ll be setting up an account on Github so make sure you use the same email address. We recommend that you use your institutional email address.
You can check that they have been set correctly by running
git config user.name
git config user.email
Colours#
git config --global color.ui "auto"
Text editor#
Jane also has to set her favourite text editor, following this table:
Editor |
Configuration command |
---|---|
Atom |
|
nano |
|
BBEdit (Mac, with command line tools) |
|
Sublime Text (Mac) |
|
Sublime Text (Win, 32-bit install) |
|
Sublime Text (Win, 64-bit install) |
|
Notepad++ (Win, 32-bit install) |
|
Notepad++ (Win, 64-bit install) |
|
Kate (Linux) |
|
Gedit (Linux) |
|
Scratch (Linux) |
|
emacs |
|
vim |
|
VS Code |
|
It is possible to reconfigure the text editor for Git whenever you want to change it.
Default Git branch naming#
Source file changes are associated with a branch
. For new learners in this
lesson, it’s enough to know that branches exist, and this lesson uses one
branch.
By default, Git will create a branch called master
when you create a new
repository with git init
(as explained in the next Episode). This term evokes
the racist practice of human slavery and the
software development community
has moved to adopt more inclusive language.
In 2020, most Git code hosting services transitioned to using main
as the
default branch. As an example, any new repository that is opened in GitHub and
GitLab default to main
. However, Git has not yet made the same change. As a
result, local repositories must be manually configured have the same main
branch name as most cloud services.
To set main
as your local default branch:
git config --global init.defaultBranch main
Note that if this value is unset in your local Git configuration, the
init.defaultBranch
value defaults to master
.
Check your configurations#
git config --list
Need help?#
Always remember that if you forget the subcommands or options of a git command,
you can access the relevant list of options typing git <command> -h
, e.g.:
git config -h
or access the corresponding Git manual by typing git <command> --help
, e.g.:
git config --help
More generally, you can get the list of available git commands and further resources of the Git manual typing:
git help
Additional references#
Check if your Git version is updated: Releases
More about setting up Git on MacOS and Windows: Git Setup and Git bash setup