Skip to content

Commit

Permalink
#99 Re-work the structure of the config lesson and add recommendation…
Browse files Browse the repository at this point in the history
…s in the discussion page
  • Loading branch information
astroDimitrios authored Dec 19, 2024
1 parent 986b30b commit 5305aa7
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 18 deletions.
48 changes: 30 additions & 18 deletions episodes/02-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ of configurations we will set as we get started with Git:
- 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`. To set up a new computer:
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"
Expand All @@ -52,9 +58,7 @@ If you elect to use a private email address with GitHub, then use GitHub's no-re

::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::: callout

## Line Endings
### Line Endings

As with other keys, when you press <kbd>Enter</kbd> or <kbd>↵</kbd> or on Macs, <kbd>Return</kbd> on your keyboard,
your computer encodes this input as a character.
Expand All @@ -69,19 +73,23 @@ You can change the way Git recognizes and encodes line endings
using the `core.autocrlf` command to `git config`.
The following settings are recommended:

On macOS and Linux:
::: group-tab

### Linux & MacOS

```bash
$ git config --global core.autocrlf input
```

And on Windows:
### Windows

```bash
$ git config --global core.autocrlf true
```

::::::::::::::::::::::::::::::::::::::::::::::::::
:::

### Text Editor

To set your preferred text editor,
find the correct configuration command from this table:
Expand Down Expand Up @@ -117,6 +125,8 @@ If you want to save your changes and quit, press <kbd>Esc</kbd> then type `:wq`

::::::::::::::::::::::::::::::::::::::::::::::::::

### 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.
Expand All @@ -127,10 +137,9 @@ $ git config --global init.defaultBranch main

::::::::::::::::::::::::::::::::::::::::: callout

## Default Git branch naming
## History of `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.
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
Expand All @@ -151,22 +160,27 @@ 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:

```bash
$ git config --global --edit
```

Let's close the file without making any additional changes. Remember, since typos in the config file will cause
issues, it's safer to view the configuration with:
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:

```bash
$ git config --list
```

And if necessary, change your configuration using the
same commands to choose another editor or update your email address.
This can be done as many times as you want.
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](../learners/discuss.md#more-advanced-git-configuration)
page has details on more recommended settings.

::::::::::::::::::::::::::::::::::::::::: callout

Expand Down Expand Up @@ -194,7 +208,7 @@ $ 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
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.:

Expand All @@ -221,5 +235,3 @@ $ git help
- Use `git config` with the `--global` option to configure a user name, email address, editor, and other preferences once per machine.

::::::::::::::::::::::::::::::::::::::::::::::::::


96 changes: 96 additions & 0 deletions learners/discuss.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ The available options are described in the manual:
$ git config --help
```

### Recommended Settings

We recommend setting the following:

```gitconfig
[merge]
ff = false
conflictStyle = diff3
[mergetool]
keepBackup = false
[fetch]
prune = true
[pull]
ff = only
```

| Setting | Value | Justification |
|----------------------|-------|------------------------------------------------------------|
| merge.ff | false | Make `git merge` always a "true merge" |
| merge.conflictStyle | diff3 | Add common ancestor to conflict markers |
| mergetool.keepBackup | false | Tidy `*.orig` files when `mergetool` finishes |
| fetch.prune | true | Automatically delete references to deleted remote branches |
| pull.ff | only | Make `git pull` only fast-forward |

These settings will be explained in later episodes
and in the follow on Git & GitHub Working Practices training.

Set them using:

```bash
$ git config --global setting value
$ git config --global merge.ff false
```

#### Aliases

In particular, you might find it useful to add aliases.
These are like shortcuts for longer Git commands.
For example, if you get sick of typing `git checkout` all the time,
Expand All @@ -63,6 +99,66 @@ we could now instead type:
$ git co f22b25e forecast.md
```

The following are some aliases others have found useful.
We recommend returning to these once you have learnt more
Git commands and become more comfortable with Git in general.

```gitconfig
[alias]
st = status
ci = commit
ca = commit -a
br = branch
co = checkout
cb = checkout -b
lg = log --oneline
graph = log --oneline --graph
dog = log --decorate --oneline --graph
sdiff = diff --staged
unstage = restore --staged
amend = commit --amend --no-edit
reword = commit --amend --only --
ff = merge --ff-only
update = "! git pull --ff-only && git push"
```

Set them using:

```bash
$ git config --global alias.<short> "<command>"
$ git config --global alias.st "status"
```

### Viewing Settings

```bash
git config --list --show-origin # Shows all configurations with their origins
git config --global --list # Shows global configurations
git config --local --list # Shows configurations for the current repository
```

### Removing Settings

The following actions can **NOT** be undone.
Be certain you wish to delete any settings.
Simply add `--unset` before the key:

```bash
$ git config --global --unset alias.st
```

You may wish to completely clear your global settings:

```bash
$ rm ~/.gitconfig
```

Or your local settings:

```bash
$ rm .git/config
```

## Styling Git's Log

A good target for customization is output from the log.
Expand Down

0 comments on commit 5305aa7

Please # to comment.