Setting Up Git
Last updated on 2025-04-15 | Edit this page
Estimated time: 5 minutes
Overview
Questions
- How do I get set up to use Git?
Objectives
- Configure
git
the first time it is used on a computer. - Understand the meaning of the
--global
configuration flag.
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,
- what our preferred text editor is,
- and that we want to use these settings globally (i.e. for every project).
Command Line Git Setup
On a command line, Git commands are written as
git verb options
, where verb
is what we
actually want to do and options
is additional optional
information which may be needed for the verb
.
Authorship
To set up a new computer:
BASH
$ git config --global user.name "Joanne Simpson"
$ git config --global user.email "j.simpson@mo-weather.uk"
Please use your own name and email address. This user name and email will be associated with your subsequent Git activity, which means that any changes pushed to GitHub, BitBucket, GitLab or another Git host server after this lesson will include this information.
For this lesson, we will be interacting with GitHub and so the email address used should be the same as the one used when setting up your GitHub account. If you are concerned about privacy, please review GitHub’s instructions for keeping your email address private.
Keeping your email private
If you elect to use a private email address with GitHub, then use
GitHub’s no-reply email address for the user.email
value.
It looks like ID+username@users.noreply.github.com
. You can
look up your own address in your GitHub email settings. Check with
your instructor whether your organisation has a policy on keeping emails
private. At the Met Office it is up to you whether to keep your email
address private.
Text Editor
To set your preferred text editor, find the correct configuration command from this table:
Editor | Configuration command |
---|---|
Atom | $ git config --global core.editor "atom --wait" |
nano | $ git config --global core.editor "nano -w" |
BBEdit (Mac, with command line tools) | $ git config --global core.editor "bbedit -w" |
Sublime Text (Mac) | $ git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w" |
Sublime Text (Win, 32-bit install) | $ git config --global core.editor "'c:/program files (x86)/sublime text 3/sublime_text.exe' -w" |
Sublime Text (Win, 64-bit install) | $ git config --global core.editor "'c:/program files/sublime text 3/sublime_text.exe' -w" |
Notepad (Win) | $ git config --global core.editor "c:/Windows/System32/notepad.exe" |
Notepad++ (Win, 32-bit install) | $ git config --global core.editor "'c:/program files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" |
Notepad++ (Win, 64-bit install) | $ git config --global core.editor "'c:/program files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" |
Kate (Linux) | $ git config --global core.editor "kate" |
Gedit (Linux) | $ git config --global core.editor "gedit --wait --new-window" |
Scratch (Linux) | $ git config --global core.editor "scratch-text-editor" |
Emacs | $ git config --global core.editor "emacs" |
Vim | $ git config --global core.editor "vim" |
gVim | $ git config --global core.editor "gvim -f" |
VS Code | $ git config --global core.editor "code --wait" |
It is possible to reconfigure the text editor for Git whenever you want to change it.
Nedit not available on Azure Spice
Nedit won’t be available on Azure SPICE VDI. Details are available in the Met Office Azure SPICE Documentation. The most similar editor in the table above is Gedit.
Exiting Vim
Note that Vim is the default editor for many programs. If you haven’t
used Vim before and wish to exit a session without saving your changes,
press Esc then type :q!
and press
Enter or ↵ or on Macs, Return. If you
want to save your changes and quit, press Esc then type
:wq
and press Enter or ↵ or on Macs,
Return.
Default Branch Name
Git (2.28+) allows configuration of the name of the branch created
when you initialize any new repository. We want to set this to
main
so it matches the cloud service we will eventually
use.
History of main
Source file changes are associated with a “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.
For versions of Git prior to 2.28, the change can be made on an
individual repository level. The command for this is in the next
episode. Note that if this value is unset in your local Git
configuration, the init.defaultBranch
value defaults to
master
.
The five commands we just ran above only need to be run once: the
flag --global
tells Git to use the settings for every
project, in your user account, on this computer.
Text Editor Git Setup
Let’s review those settings and test our core.editor
right away:
Let’s close the file without making any additional changes. Since typos in the config file will cause issues, it’s safer to view the configuration with:
And alter the configuration via the command line. You can re-run the commands above as many times as you want to change your configuration. The discussion page has details on more recommended settings.
Proxy
In some networks you need to use a proxy. If this is the case, you may also need to tell Git about the proxy:
To disable the proxy, use
Git Help and Manual
If you forget the subcommands or options of a git
command, you can access the relevant list of options typing
git <command> -h
or access the corresponding Git
manual by typing git <command> --help
, e.g.:
While viewing the manual, remember the :
is a prompt
waiting for commands and you can press Q to exit the
manual.
More generally, you can get the list of available git
commands and further resources of the Git manual typing:
Key Points
- Use
git config
with the--global
option to configure a user name, email address, editor, and other preferences once per machine.