Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions 02-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ A branch is just a reference to a commit, it has a human-readable name
and identifier. Instead of using the SHA-1 hash to reference a commit we can
now use the name of a branch.

When creating a repository using `git init` a branch named 'master' is created
When creating a repository using `git init` a branch named 'main' is created
for us, it is currently pointed at our latest commit.

![The current state of our repository](./img/basic-branch.png)

Let's designate 'master' as the branch for our main line of development,
Let's designate 'main' as the branch for our main line of development,
anything on that branch should be stable. If we want to test out new features
without breaking the main line then we can create new branches.

## Practical One

We want to add a new file to our current project, but we don't want to mess up
'master'.
'main'.

#### View the current branches

We can see all of the branches in our repository.

```bash
git branch
# stdout: master
# stdout: main
```

#### Create a new branch from master
#### Create a new branch from main

To add our new feature we want to add a new branch. Our new feature is adding
information about our favourite animal so let's call the branch something
Expand All @@ -36,7 +36,7 @@ descriptive like 'favourite-animal'.
```bash
git branch favourite-animal
# If we do a 'git branch' now we'll see our new branch is created, but we're
# still on master. Let's 'checkout' our new branch.
# still on main. Let's 'checkout' our new branch.

git checkout favourite-animal
```
Expand Down Expand Up @@ -87,13 +87,13 @@ cat .git/HEAD
## Practical Two

We have created a branch that has information about our favourite animal. Now
let's create another branch from master and add information about our favourite
let's create another branch from main and add information about our favourite
TV show. We are currently on the branch 'favourite-animal'. We need to create
our new branch from master.
our new branch from main.

```bash
# Create a new branch named favourite-show from the branch master
git branch favourite-show master
# Create a new branch named favourite-show from the branch main
git branch favourite-show main
git checkout favourite-show
```

Expand Down
14 changes: 7 additions & 7 deletions 03-merging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ In the last section, we learned about creating new branches. Often branches are
created temporarily to work on a specific piece of work. When that work is
ready, then those changes are brought back into the main line again.

Remember the branches from the last section? Originally there was the master
Remember the branches from the last section? Originally there was the main
branch, and then we created a branch called 'favourite-animal', where we made
changes. We can now merge those changes back into master branch, and delete the
changes. We can now merge those changes back into main branch, and delete the
'my-new-branch' since we won't need it anymore.

## Practical One - Fast-forward merging

The simplest form of merging is *fast-forward* merging. Since branches are just
references to commits, and 'favourite-animal' is a direct descendant of master;
we can just update master to point to the same commit as 'favourite-animal'.
references to commits, and 'favourite-animal' is a direct descendant of main;
we can just update main to point to the same commit as 'favourite-animal'.

This is the default way that git will merge when the target branch is an
ancestor of the source branch. First, `checkout` the target branch (master in
ancestor of the source branch. First, `checkout` the target branch (main in
this case), and then use the `merge` subcommand to bring the changes from the
source branch (favourite-animal) into this branch:

```bash
git checkout master
git checkout main

git merge favourite-animal
```
Expand All @@ -42,7 +42,7 @@ message.

![Before creating a merge commit](./img/basic-merging-before.png)

While on the master branch, we can now merge the changes from the
While on the main branch, we can now merge the changes from the
'favourite-show' branch as follows:

``` bash
Expand Down
4 changes: 2 additions & 2 deletions 04-conflicts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the action, and asks you to intervene.
First, let's make a new branch and add a file:

``` bash
git checkout -b left master
git checkout -b left main

echo "Left is the best" > conflict.txt

Expand All @@ -27,7 +27,7 @@ Next, for the purposes of demonstration, let's create another branch,
called `right`:

```bash
git checkout -b right master
git checkout -b right main

echo "Right is the best" > conflict.txt
git add conflict.txt
Expand Down
10 changes: 5 additions & 5 deletions 07-rebasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Why rewrite history?
Rebasing and Merging are two methods that achieve the same goal - the integration of changes from one branch into another branch


![rebase on master](img/01.gif)
![rebase on main](img/01.gif)
![rebase on feature](img/02.gif)

## Prerequisites
Expand All @@ -34,8 +34,8 @@ git clone git@github.com:<github_username>/git-tutorial.git
git fetch
git checkout rebase

# The rebase branch was branched from master a while ago
# It's out of date (master has moved on)
# The rebase branch was branched from main a while ago
# It's out of date (main has moved on)
# And there's bad commits in our history that we're going to fixup
git log --pretty=oneline

Expand All @@ -45,11 +45,11 @@ git rebase -i HEAD~4 # Note the lack of a branch
# Fix up the commits - think about re-ordering or (s)quashing
# the version bumps and (r)eword the commit messages.
# Also, delete commits that are of no value
git rebase origin/master
git rebase origin/main

# Alternatively:
# We can do both a history rewrite and a rebase via:
git rebase -i origin/master
git rebase -i origin/main
```

# Next Section
Expand Down
8 changes: 4 additions & 4 deletions 08-stashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ git status

# See what is stashed in this repository
$ git stash list
stash@{0}: On master: experimental work with hello.txt
stash@{0}: On main: experimental work with hello.txt
```
Now make another change to _hello.txt_ before moving on to the next section
```bash
# We want to stash your last change, check the status and our stash list
$ git stash
$ git status
On branch master
On branch main
nothing to commit, working tree clean
$ git stash list
stash@{0}: WIP on master: 21954be rerge branch 'favourite-show'
stash@{1}: On master: experimental work with hello.txt
stash@{0}: WIP on main: 21954be rerge branch 'favourite-show'
stash@{1}: On main: experimental work with hello.txt

# Restore top/first stash (stash@{0}) & remove it from the list
$ git stash pop # == apply && drop
Expand Down
2 changes: 1 addition & 1 deletion 09-cherry-picking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Apply the changes introduced by some existing commits

Our main use-case for git-cherry-pick is for taking some bugfix commits from one branch, and applying them to another (e.g. a release branch and master)
Our main use-case for git-cherry-pick is for taking some bugfix commits from one branch, and applying them to another (e.g. a release branch and main)

## Prerequisite
Ensure your current directory is that of the cloned repository in the previous practical.
Expand Down
2 changes: 1 addition & 1 deletion 11-bisecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In the `git-tutorial` repo:

```bash
git checkout bisect
# Our bisect branch is a little ahead of of master (500 commits)
# Our bisect branch is a little ahead of of main (500 commits)
# At some point, a commit slipped in that means our app doesn't start
# and our tests fail.
# Lets use git bisect to find the broken commit
Expand Down
2 changes: 1 addition & 1 deletion 12-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Aliases are really useful

Lots of other useful aliases and config customization examples here:

https://github.com/matthewmccullough/dotfiles/blob/master/gitconfig
https://github.com/matthewmccullough/dotfiles/blob/main/gitconfig



Expand Down
14 changes: 7 additions & 7 deletions 14-under-the-covers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ $ tree -L 1 ./.git
`COMMIT_EDITMSG` can be useful with the hub command to create a pull-request on github with a single command

```bash
# Create a PR against master branch of the repo in the feedhenry org
# Create a PR against main branch of the repo in the feedhenry org
# with the contents of the most recent commit message as the description
git pull-request -b feedhenry:master -F ./.git/COMMIT_EDITMSG
git pull-request -b feedhenry:main -F ./.git/COMMIT_EDITMSG
```

## Git objects - what are they?
Expand Down Expand Up @@ -70,8 +70,8 @@ Porcelain provides a more user-friendly interface to the plumbing
https://git.io/v1Bt5

```bash
# Create a new branch from master & checkout
git co -b ungit master
# Create a new branch from main & checkout
git co -b ungit main

# Make a new blob object
blob_sha1=$(echo "Let's ungit" | git hash-object -w --stdin)
Expand Down Expand Up @@ -103,10 +103,10 @@ c838b24 HEAD@{1}: merge c838b2447de706f53eaabed16c371abbb6d82b03: Fast-forward
e29b7ee HEAD@{2}: checkout: moving from cp-conflict-example to ungit
bf196ea HEAD@{3}: commit (cherry-pick): Bumping version to 2.0.8
e29b7ee HEAD@{4}: checkout: moving from cp-example to cp-conflict-example
b2d9004 HEAD@{5}: checkout: moving from master to cp-example
e29b7ee HEAD@{6}: checkout: moving from cp-example to master
b2d9004 HEAD@{5}: checkout: moving from main to cp-example
e29b7ee HEAD@{6}: checkout: moving from cp-example to main
b2d9004 HEAD@{7}: cherry-pick: name change
e29b7ee HEAD@{8}: checkout: moving from master to cp-example
e29b7ee HEAD@{8}: checkout: moving from main to cp-example
e29b7ee HEAD@{9}: clone: from git@github.com:fheng/git-tutorial.git

# Checkout a previous state
Expand Down