# Setting up Git

### Five Commands

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.

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.

We need to define our name and email address. Our user name and email will be associated with our subsequent Git activity, which means that any changes pushed to [GitHub](https://github.com/), [BitBucket](https://bitbucket.org/), [GitLab](https://about.gitlab.com/) or another Git host server will include this information.

* Define user name
  * `git config --global user.name "Vlad Dracula"`
  * Make sure to change Vlad Dracula to your own user name

* Define email address
  * `git config --global user.email "vlad@tran.sylvan.ia"`
  * Make sure to change the email address to your own
  * 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 our GitHub account.
  * If you are concerned about privacy, please review \[[GitHub’s instructions for keeping your email address private](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/setting-your-commit-email-address).
  * If you decide to keep your email private with GitHub, then use that same email address for the user.email value, e.g. <username@users.noreply.github.com> replacing username with your GitHub one.

* As with other keys, when you hit Enter or ↵ or on Macs, Return on your keyboard, your computer encodes this input as a character. Different operating systems use different character(s) to represent the end of a line. (You may also hear these referred to as newlines or line breaks.) Because Git uses these characters to compare files, it may cause unexpected issues when editing a file on different machines. Though it is beyond the scope of this lesson, you can read more about this issue [in the Pro Git book](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf). You can change the way Git recognizes and encodes line endings using the `core.autocrlf` command to git config.
  * On macOS and Linux:
    * `git config --global core.autocrlf input`
  * On Windows:
    * `git config --global core.autocrlf false`

* Set our favorite text editor
  \*

  ```
  <figure><img src="/files/uGAIycwDh09UyHJkn0qL" alt=""><figcaption></figcaption></figure>
  ```

* Set the name of the branch to main
  * Git (2.28+) allows configuration of the name of the branch created when you initialize any new repository. We can use this feature to set it to main so it matches the cloud service we will eventually use.
  * `git config --global init.defaultBranch main`
  * 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](https://github.com/github/renaming) 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 commands in the above five links 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.

### Check Your Settings

We can check our settings at any time:

```
git config --list
```

We can change our configuration as many times as we want: use the same commands to choose another editor or update our email address.

### Proxy

In some networks you need to use a [proxy](https://en.wikipedia.org/wiki/Proxy_server). If this is the case, you may also need to tell Git about the proxy:

```
git config --global http.proxy proxy-url
git config --global https.proxy proxy-url
```

To disable the proxy, use

```
git config --global --unset http.proxy
git config --global --unset https.proxy
```

### Git Help and Manual

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 or access the corresponding Git manual by typing git \<command> --help, e.g.:

```
git config -h
git config --help
```

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:

```
git help
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/version-control-with-git/setting-up-git.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
