Skip to content

Commit

Permalink
Merge pull request #259 from coderefinery/rename-master
Browse files Browse the repository at this point in the history
use main as default branch and git switch instead of checkout  closes #256
  • Loading branch information
johanhellsvik authored Sep 6, 2023
2 parents d63b83a + 1d91dd4 commit 3490a72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions content/centralized.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Features:
- Typically all developers have both read and write permissions (double-headed arrows).
- Suited for cases where **all developers are in the same group or organization or project**.
- **Everybody who wants to contribute needs write access**.
- Good idea to write-protect the main branch (typically `master` or `main`).
- Good idea to write-protect the main branch (typically `main`).

Real life examples:

Expand Down Expand Up @@ -184,10 +184,10 @@ Here and in what follows, "c1" is a commit, "b1" etc. are commits on side branch
and "m1" is a merge commit.
- We clone the entire history, all branches, all commits. In our case, we have one branch (we did not include *all branches* when creating our repository from template) and we have only one commit (*initial commit*).
- `git clone` creates pointers `origin/master` so you can see the branches of the origin.
- `git clone` creates pointers `origin/main` so you can see the branches of the origin.
- `origin` refers to where we cloned from.
- `origin` is a shortcut for the full URL.
- `origin/master` is a read-only pointer.
- `origin/main` is a read-only pointer.
- The branches starting with `origin/` only move during `git pull` or `git fetch` or `git push`.
- Only `git pull` or `git fetch` or `git push` require network.
- All other operations are local operations.
Expand All @@ -205,11 +205,11 @@ Try to find out where this repository was cloned from using `git remote -v`.

### Step C. Create a branch `yourname-somefeature` pointing at your commit

Create a branch from the current `master`. Also adapt "yourname-somefeature" to a better name:
Create a branch from the current `main`. Also adapt "yourname-somefeature" to a better name:

```console
$ git branch yourname-somefeature master
$ git checkout yourname-somefeature
$ git branch yourname-somefeature main
$ git switch yourname-somefeature
```

The `yourname-` prefix has no special meaning here (not like `origin/`): it is just part of a
Expand Down Expand Up @@ -308,7 +308,7 @@ discuss what you see.

### Step H. Submit a pull request

Submit a pull request from your branch towards the `master` branch.
Submit a pull request from your branch towards the `main` branch.
Do this through the web interface.

Meaning of a pull request: think of it as change proposal. In a popular project, it means that anyone can
Expand Down Expand Up @@ -389,7 +389,7 @@ At this stage demonstrate how to suggest small changes to pull/merge requests:
**Protected branches**
- A good setting for large projects is to make the `master` or `main` branch **protected** and all changes to it have to go
- A good setting for large projects is to make the `main` branch **protected** and all changes to it have to go
through code review.
- Centralized workflow with protected branches is a good setup for many projects.
Expand All @@ -407,8 +407,8 @@ exercise repository** but we do this together in the main room so that we can
discuss this step and ask questions.

```console
$ git checkout master
$ git pull origin master
$ git switch main
$ git pull origin main
```

```{figure} img/centralized/06-remote.svg
Expand Down Expand Up @@ -456,19 +456,19 @@ for more examples.
makes a new change (create a new file)
but without creating a new branch.
1. You all create a new file in the master branch, stage and commit your change locally.
1. You all create a new file in the main branch, stage and commit your change locally.
2. Try to push the change to the upstream repository:
```console
$ git push origin master
$ git push origin main
```
You probably see something like this:
```console
$ git push
To https://github.com/user/repo.git
! [rejected] master -> master (non-fast-forward)
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
Expand All @@ -489,7 +489,7 @@ for more examples.
````{discussion} Discussion: How to make changes to remote branches
If there is a remote branch `somefeature`, we can create a local branch and start tracking `origin/somefeature` like this:
```console
$ git checkout somefeature
$ git switch somefeature
```
Once we track a remote branch, we can pull from it and push to it:
Expand Down
16 changes: 8 additions & 8 deletions content/distributed.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ its content. For example:

```console
$ git branch myname-feature # describes both who it belongs to and the purpose
$ git checkout myname-feature
$ git switch myname-feature
```

**On the new branch create a new file** which will hold your recipe,
Expand Down Expand Up @@ -321,7 +321,7 @@ local

### Step E: Open a pull request

Then file a pull request from the branch on your fork towards the master branch on the central repository.
Then file a pull request from the branch on your fork towards the main branch on the central repository.

````{admonition} Pictorial representation for steps D and E
---
Expand Down Expand Up @@ -416,9 +416,9 @@ instead of aliases like `origin` or `upstream`.
Here we pull from the central repo and push to our fork:
```console
$ git checkout master
$ git pull <central-repository-url> master
$ git push <fork-url> master
$ git switch main
$ git pull <central-repository-url> main
$ git push <fork-url> main
```
Here is a pictorial representation of this part:
Expand Down Expand Up @@ -456,8 +456,8 @@ local
```
```console
$ git checkout master
$ git merge central/master
$ git switch main
$ git merge central/main
```
```{figure} img/forking/github-remote-03.svg
Expand All @@ -476,7 +476,7 @@ local
```
```console
$ git push origin master
$ git push origin main
```
```{figure} img/forking/github-remote-03.svg
Expand Down
4 changes: 2 additions & 2 deletions content/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the basics.
* **pull**: Fetch (above) and then merge
* **origin**: Default name for a remote repository.
* **origin/NAME**: A branch name which represents a remote branch.
* **master**: Default name for main branch.
* **main**: Default name for main branch.
* **merge**: Combine the changes on two branches.
* **conflict**: When a merge has changes that affect the same lines,
git can not automatically figure out what to do. It presents the
Expand Down Expand Up @@ -55,7 +55,7 @@ Status:

General work:

* `git checkout <branch-name>`: Make a branch active.
* `git switch <branch-name>`: Make a branch active.
* `git push [<remote-name>] [<branch>:<branch>]`: Send commits and
update the branch on the remote.
* `git pull [<remote-name>] [<branch-name>]`: Fetch and then merge
Expand Down
2 changes: 1 addition & 1 deletion content/remotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

- **repository**: The project, contains all data and history (commits, branches, tags).
- **commit**: Snapshot of the project, gets a unique identifier (e.g. `c7f0e8bfc718be04525847fc7ac237f470add76e`).
- **branch**: Independent development line. The main development line is often called `main` or `master`.
- **branch**: Independent development line. The main development line is often called `main`.
- **tag**: A pointer to one commit, to be able to refer to it later. Like a [commemorative plaque](https://en.wikipedia.org/wiki/Commemorative_plaque)
that you attach to a particular commit (e.g. `phd-printed` or `paper-submitted`).
- **cloning**: Copying the whole repository to your laptop - the first time. It is not necessary to download each file one by one.
Expand Down

0 comments on commit 3490a72

Please sign in to comment.