Skip to content

Commit

Permalink
Add git merging
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimonrichard committed Oct 26, 2024
1 parent 1bdbe35 commit c38ef82
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
32 changes: 26 additions & 6 deletions src/ch2-git.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# What is Git?

### Version control
Git is a version control system (VCS), which means that it saves, compares, and manages changes to files (usually code files) over time.

Git is a version control system (VCS) that allows developers to track changes to their code over time.
This may seem innocuous, but it's actually vital to the development cycle. Virtually all professional code is managed by some VCS, and git is by far the most common.

It basically takes a picture of what your files look like at the moment and stores a reference to a snapshot.
## Use cases

### Code colaboration
### Tracking file changes over time

Lets say that you need to work on a coding project with your lab partner. How can both of you work on the same codebase?
Have you ever been scared to work on your code after completing a feature because you didn't break it? Git fixes this by allowing you to take a snapshot (or "commit") of your code, which you can always go back to by running a single command (`git checkout ...` or `git reset ...`).

Git makes this possible
Making multiple commits (best practice is a commit for each feature) throughout the progression of a project allows you to revert at any time to any "milestone." You'll never lose your work again[^1].

### Working on different versions of your code at the same time

Git branches allow you to work on multiple versions of your code base at the same time. For example, if you want to maintain an old, released version (e.g. adding security patches) while continuing feature development for the latest version, you could create a branch called `v1.0.0` and a branch called `dev`.

By default, git repositories have one branch named `master` or `main`. This is often used either for development or for the latest stable version of the software.

### Code collaboration

Branches (or forked repositories on a platform like GitHub) can be used by multiple developers to collaborate on the same code base. Usually, each developer works on their own branch and implements a feature. Once that feature is complete, they *merge* the branch into the `main` or `master` branch.

### Storing code remotely

Git can be used with platforms like [GitHub](https://github.com) or [GitLab](https://gitlab.com) to manage code stored in the cloud. This is an important part of the modern development cycle.

Typically, a developer creates a branch, implements their feature (or reaches some stopping point), and then commits their changes. After they commit their changes, they *push* it up to the server hosting the main code base so that others can access it.

For smaller projects, developers may skip the "creating a branch" step and commit new code directly to the `main` branch.

[^1]: Unless you delete or lose the git repository itself, or manually delete commits.
29 changes: 29 additions & 0 deletions src/ch2.2-using-git.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,32 @@ This command creates a commit:
A good way of visualizing how this works

![Drawing-2](./images/IMG_96E3138F72ED-1.jpeg)


### Merging branches

To bring the latest changes in `branch_a` into `main`, we would first switch to the main branch...
```bash
git checkout main
```
and then run the `git merge` command.
```bash
git merge branch_a
```

If the files modified in `main` and `branch_a` (after `branch_a` was created or after the last merge) are mutually exclusive, then git should be able to do this automatically. However, if the same file was modified in both branches, you probably encounter this:
```
CONFLICT (content): Merge conflict in my_file.txt
Automatic merge failed; fix conflicts and then commit the result.
```

Before you do anything else, you will need to fix the merge conflicts. Git represents these conflicts within each file using the following template (or something similar, if you've modified the default settings):
```
<<<<<<< HEAD
Change in the main branch
=======
Change in branch_a
>>>>>>> branch_a
```

To resolve this, replace the text above with the final desired version (it could be one or the other, or a combination of both). Once you've resolved all of the conflicts in (and saved) each file, stage the files and create a new commit. This completes the merge process.
12 changes: 6 additions & 6 deletions src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ During this workshop, we seek to answer the following questions for Linux:
- [What is a Linux distribution ("distro")?](./ch1-linux.md#what-is-a-linux-distribution)
- [What is a Desktop Environment?](./ch1-linux.md#what-is-a-desktop-environment)
- [Why should I care about Linux?](./ch1-linux.md#why-should-i-care-about-linux)
- How do you install popular Linux distros like Ubuntu, Debian, Mint, Fedora, and others?
- How to use the terminal
- [How do you install popular Linux distros like Ubuntu, Debian, Mint, Fedora, and others?](./ch1.1-linux-installation.md)
- [How to use the terminal](./ch1.2-linux-terminal.md)

And for git:

- [What is git? Why Git?](./ch2-git.md)
- Why is it important? What are the use cases?
- How do you install git (on Windows, MasOS, and Linux)?
- How do you use git from the terminal?
- [What is git?](./ch2-git.md)
- [Why is it important? What are the use cases?](./ch2-git.md#use-cases)
- [How do you install git (on Windows, MasOS, and Linux)?](./ch2.1-git-installation.md)
- [How do you use git from the terminal?](./ch2.2-using-git.md)
- Git in VSCode


Expand Down

0 comments on commit c38ef82

Please sign in to comment.