Skip to content

Commit 2ecb6fb

Browse files
committed
source commit: dcd02e0
0 parents  commit 2ecb6fb

30 files changed

+702
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Contributor Code of Conduct"
3+
---
4+
5+
As contributors and maintainers of this project,
6+
we pledge to follow the [The Carpentries Code of Conduct][coc].
7+
8+
Instances of abusive, harassing, or otherwise unacceptable behavior
9+
may be reported by following our [reporting guidelines][coc-reporting].
10+
11+
12+
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html
13+
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html

LICENSE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: "Licenses"
3+
---
4+
5+
## Instructional Material
6+
7+
All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry)
8+
instructional material is made available under the [Creative Commons
9+
Attribution license][cc-by-human]. The following is a human-readable summary of
10+
(and not a substitute for) the [full legal text of the CC BY 4.0
11+
license][cc-by-legal].
12+
13+
You are free:
14+
15+
- to **Share**---copy and redistribute the material in any medium or format
16+
- to **Adapt**---remix, transform, and build upon the material
17+
18+
for any purpose, even commercially.
19+
20+
The licensor cannot revoke these freedoms as long as you follow the license
21+
terms.
22+
23+
Under the following terms:
24+
25+
- **Attribution**---You must give appropriate credit (mentioning that your work
26+
is derived from work that is Copyright (c) The Carpentries and, where
27+
practical, linking to <https://carpentries.org/>), provide a [link to the
28+
license][cc-by-human], and indicate if changes were made. You may do so in
29+
any reasonable manner, but not in any way that suggests the licensor endorses
30+
you or your use.
31+
32+
- **No additional restrictions**---You may not apply legal terms or
33+
technological measures that legally restrict others from doing anything the
34+
license permits. With the understanding that:
35+
36+
Notices:
37+
38+
* You do not have to comply with the license for elements of the material in
39+
the public domain or where your use is permitted by an applicable exception
40+
or limitation.
41+
* No warranties are given. The license may not give you all of the permissions
42+
necessary for your intended use. For example, other rights such as publicity,
43+
privacy, or moral rights may limit how you use the material.
44+
45+
## Software
46+
47+
Except where otherwise noted, the example programs and other software provided
48+
by The Carpentries are made available under the [OSI][osi]-approved [MIT
49+
license][mit-license].
50+
51+
Permission is hereby granted, free of charge, to any person obtaining a copy of
52+
this software and associated documentation files (the "Software"), to deal in
53+
the Software without restriction, including without limitation the rights to
54+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
55+
of the Software, and to permit persons to whom the Software is furnished to do
56+
so, subject to the following conditions:
57+
58+
The above copyright notice and this permission notice shall be included in all
59+
copies or substantial portions of the Software.
60+
61+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67+
SOFTWARE.
68+
69+
## Trademark
70+
71+
"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library
72+
Carpentry" and their respective logos are registered trademarks of [Community
73+
Initiatives][ci].
74+
75+
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/
76+
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode
77+
[mit-license]: https://opensource.org/licenses/mit-license.html
78+
[ci]: https://communityin.org/
79+
[osi]: https://opensource.org

branches.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
title: "Branches"
3+
teaching: 15
4+
exercises: 15
5+
---
6+
7+
:::::::::::::::::::::::::::::::::::::: questions
8+
9+
- Why use branches?
10+
- How do we use branches?
11+
12+
::::::::::::::::::::::::::::::::::::::::::::::::
13+
14+
::::::::::::::::::::::::::::::::::::: objectives
15+
16+
- Be able to create and merge a branch
17+
18+
::::::::::::::::::::::::::::::::::::::::::::::::
19+
20+
21+
22+
23+
24+
## About Branches
25+
26+
Branches are independent development lines. Working independently, you can likely get away with using git without creating any branches, as in the first diagram in the figure below. However, when you begin to work with others, branches allow team members to work on the code without impacting the work of other developers or users.
27+
28+
![Figure showing three graph diagrams representing different repository states. Each is a graph consisting of vertices (circles) and directed edges (arrows) where each horizontal path is a branch. The first shows a single path representing a repository with a single main branch, the second has two branches, a main and a feature branch, and the third has three branches, a main and two feature branches.](../fig/branches/branches.png){alt="" width="75%"}
29+
*These graph diagrams show repositories with different numbers of branches. The vertices, or circles, in these graphs show different commits, and each horizontal path is a branch. The first shows a repository with 1 main branch, the second a repository with 1 main and 1 feature branch, and the third repository 1 main and 2 feature branches.*
30+
31+
Branches can have a few different purposes. Branches created to develop a specific feature are referred to as feature branches, and are often short-lived. Branches can also be used for longer-term purposes, such as having separate development and production branches. How you organize and use branches in your project is referred to as a branching strategy, which we will cover more when we talk about git workflows.
32+
33+
Changes made in one branch can be brought into another branch with a merge. For example, when a feature branch is completed it may be merged into the main branch. And, if while you are working on a feature branch the main branch changes, you can merge the changes from the main branch into your feature branch while you are still working.
34+
35+
## How to Work with Branches
36+
37+
### Creating Branches
38+
39+
You can create a branch on your local clone of the repository. If didn't just clone the repository it is always good to make sure you have any recent changes to the main branch by checking out the main branch and running "git pull":
40+
41+
```shell
42+
git checkout main
43+
git pull
44+
```
45+
46+
Then, to create a branch we can run:
47+
48+
```shell
49+
git checkout -b my_new_branch
50+
```
51+
52+
This will create the branch `my_new_branch` and move you to the new branch. If you run `git status` at this point it will display `On branch my_new_branch`. Making and committing any changes will only update `my_new_branch`.
53+
54+
![Figure showing the process of creating a branch. First a graph diagram of a repository is shown with two commits on the main branch. To the left is an arrow with the text "git checkout -b my_branch" followed by the same repository with the new feature branch added. A smiley face is used on each diagram to show where you are in the repository, the first has it on the second commit in the main branch, the second on the feature branch.](../fig/branches/create_branch.png){alt="" width="75%"}
55+
*Creating a new branch. When you run `git checkout -b my_branch` your new branch gets created and checked out, meaning you are now on your new branch (represented by the smiley face). Any commits you make will be on this branch until you checkout another one.*
56+
57+
![Figure creating commits on a branch. First a graph diagram of a repository is shown with two commits on the main branch and one on a feature branch. To the left is an arrow with the text "git commit (x2)", followed by the same repository with to additional commits on the feature branch. A smiley face is used on each diagram to show where you are in the repository, each on the last commit on the feature branch.](../fig/branches/commit_branch.png){alt="" width="75%"}
58+
*Every time you run the `git commit` command the commit will be added to your current branch.*
59+
60+
The first time you push your branch to the remote repository, you will need to publish the branch by running run:
61+
62+
```shell
63+
git push --set-upstream origin my_new_branch
64+
```
65+
66+
After this any commits can be pushed with a simple `git push`.
67+
68+
### Changing Branches
69+
70+
If you need to switch to another existing branch you can use the `git checkout` command. For example, to switch back to the main branch you can run:
71+
72+
```shell
73+
git checkout main
74+
```
75+
76+
Remember, if you aren't sure which branch you are on you can run `git status`. It is good practice before you start making changes to any of your files to check that you are on the right branch with `git status`, particularly if you haven't touched the code recently.
77+
78+
![Figure showing the process of changing, or checking out a branch. First a graph diagram of a repository is shown with two commits on the main branch and three on the feature branch. A smiley face is on the third commit of the feature branch to show the current location. To the left is an arrow with the text "git checkout main" followed by the same repository with the smiley face now on the second commit in the main branch.](../fig/branches/checkout_branch.png){alt="" width="85%"}
79+
*Switching branches using `git checkout`.*
80+
81+
### Merging Branches
82+
83+
Bring the changes from one branch into another branch by merging them. When you merge branches, changes from the specified branch are merged into the branch that you currently have checked out. For example,
84+
85+
```shell
86+
git checkout my_new_branch
87+
git merge main
88+
```
89+
90+
will merge any changes introduced to `main` into the `my_new_branch`. Merging in this direction is especially useful when you've been working on `my_new_branch` for a while and `main` has changed in the meantime.
91+
92+
![Figure showing the process of merging the main branch into the feature branch. First a graph diagram of a repository is shown with a main and feature branch. The feature branch with three commits splits off the main branch after two commits, and the main branch has an additional two commits after the split. A smiley face is on the third commit of the feature branch to show the current location. Below is an arrow with the text "git merge main" followed by the same repository with a new arrow from the last commit on the main branch to a new commit on the feature branch, showing the changes from the main branch have been merged into the changes on the feature branch.](../fig/branches/merge_into_branch.png){alt="" width="60%"}
93+
*Merging new commits from the main branch into the feature branch with `git merge main`.*
94+
95+
When development is complete on `my_new_branch`, it would be merged into `main`:
96+
97+
```shell
98+
git checkout main
99+
git merge my_new_branch
100+
```
101+
102+
![Figure showing the process of merging the feature branch into the main branch. First a graph diagram of a repository is shown with a main and feature branch. The feature branch with three commits splits off the main branch after two commits. A smiley face is on the second commit of the main branch to show the current location. Below is an arrow with the text "git merge my_branch" followed by the same repository a new commit on the main branch with two arrows from the main and feature branches, showing the changes from the feature branch have been merged into main branch.](../fig/branches/merge_into_main.png){alt="" width="50%"}
103+
*Merging new commits the feature branch into the main branch with `git merge my_branch`.*
104+
105+
Git will do its best to complete the merge automatically. For example, if none of the changes have happened in the same lines of code, things will usually merge cleanly. If the merge can't complete automatically, this is called a merge conflict. Any conflicts in the files must be resolved before the merge can be completed.
106+
107+
## Merge vs Rebase
108+
109+
There is another way to introduce changes from one branch to another: rebasing. A rebase rewrites history. For example, if there are new commits on the main branch while you are working on a feature branch, you could merge those commits into your feature branch, as we describe above. This creates a new commit with two parent commits: one in your feature branch, one in the main branch. Alternatively, you can rebase your feature branch onto the new end of the main branch with `git rebase main`. Rebasing "replays" your feature branch commits onto the new commits of the main branch, as if you started your branch there.
110+
111+
![Figure showing the process of rebasing the feature branch onto new commits in the main branch. First a graph diagram of a repository is shown with a main and feature branch. The feature branch with three commits splits off the main branch after two commits. A smiley face is on the third commit of the feature branch to show the current location. Below is an arrow with the text "git rebase main" followed by the same repository, but the feature branch now splits off the main branch at the last commit.](../fig/branches/rebase.png){alt="" width="50%"}
112+
*Rebasing the feature branch onto new commits in the main branch with `git rebase main`.*
113+
114+
Rebasing creates a cleaner history, without the extra merge commit. However, rebases never be done on public branches that others might be using or even looking at. It will result in your repository and everyone else's having different history, which can be confusing and difficult to fix. If no one else is looking at your branch, especially if you haven't published it yet, rebasing is safe.
115+
116+
## Activity
117+
118+
Everyone:
119+
120+
- Create a new branch in your local clone
121+
- Publish the branch to the remote repository
122+
- Make a small change, commit, and push
123+
- Look at the remote repository, look at your change and your group's changes
124+
125+
Now, **all but one** should run the following:
126+
127+
```shell
128+
git pull
129+
git checkout main
130+
git merge branch_name
131+
git push
132+
```
133+
134+
Did anyone run into merge conflicts? How might this have been prevented?
135+
136+
There should be one team member who still has an unmerged branch at the end of this exercise.
137+
138+
## Additional Resources
139+
140+
- [Code Refinery: Branches](https://coderefinery.github.io/git-intro/branches/)
141+
- [Code Refinery: Conflict Resolution](https://coderefinery.github.io/git-intro/conflicts/)
142+
- [Atlassian Git Tutorials: Merging vs. Rebasing](https://www.atlassian.com/git/tutorials/merging-vs-rebasing)
143+
- [Slide version of this lesson](https://github.com/INTERSECT-training/collaborative-git/blob/main/presentations/CollaborativeGit.pdf)
144+
145+
146+
147+
148+
::::::::::::::::::::::::::::::::::::: keypoints
149+
150+
- Branches allow team members to work on code without impacting the work of other developers or users
151+
- Create a new branch with the git checkout -b command, for example: git checkout -b my_branch
152+
- Change to another branch with the git checkout command, for example: git checkout my_other_branch
153+
- Merge my_branch into the current branch with with the git merge command, for example: git merge my_branch
154+
- Rebasing rewrites history and can sometimes be used instead of merge, where appropriate
155+
- Never rebase on a public branch
156+
157+
::::::::::::::::::::::::::::::::::::::::::::::::

config.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#------------------------------------------------------------
2+
# Values for this lesson.
3+
#------------------------------------------------------------
4+
5+
# Which carpentry is this (swc, dc, lc, or cp)?
6+
# swc: Software Carpentry
7+
# dc: Data Carpentry
8+
# lc: Library Carpentry
9+
# cp: Carpentries (to use for instructor training for instance)
10+
# incubator: The Carpentries Incubator
11+
#
12+
# This option supports custom types so lessons can be branded
13+
# and themed with your own logo and alt-text (see `carpentry_description`)
14+
# See https://carpentries.github.io/sandpaper-docs/editing.html#adding-a-custom-logo
15+
carpentry: 'intersect'
16+
17+
# Alt-text description of the lesson.
18+
carpentry_description: 'Collaborative Git'
19+
20+
# Overall title for pages.
21+
title: 'Collaborative Git' # FIXME
22+
23+
# Date the lesson was created (YYYY-MM-DD, this is empty by default)
24+
created: ~ # FIXME
25+
26+
# Comma-separated list of keywords for the lesson
27+
keywords: 'software, data, lesson, The Carpentries' # FIXME
28+
29+
# Life cycle stage of the lesson
30+
# possible values: pre-alpha, alpha, beta, stable
31+
life_cycle: 'alpha' # FIXME
32+
33+
# License of the lesson
34+
license: 'CC-BY 4.0'
35+
36+
# Link to the source repository for this lesson
37+
source: 'https://github.com/INTERSECT-training/collaborative-git' # FIXME
38+
39+
# Default branch of your lesson
40+
branch: 'main'
41+
42+
# Who to contact if there are any issues
43+
contact: 'team@carpentries.org' # FIXME
44+
45+
# Navigation ------------------------------------------------
46+
#
47+
# Use the following menu items to specify the order of
48+
# individual pages in each dropdown section. Leave blank to
49+
# include all pages in the folder.
50+
#
51+
# Example -------------
52+
#
53+
# episodes:
54+
# - introduction.md
55+
# - first-steps.md
56+
#
57+
# learners:
58+
# - setup.md
59+
#
60+
# instructors:
61+
# - instructor-notes.md
62+
#
63+
# profiles:
64+
# - one-learner.md
65+
# - another-learner.md
66+
67+
# Order of episodes in your lesson
68+
episodes:
69+
- introduction.md
70+
- branches.md
71+
- pr.md
72+
- git-workflows.md
73+
74+
# Information for Learners
75+
learners:
76+
77+
# Information for Instructors
78+
instructors:
79+
80+
# Learner Profiles
81+
profiles:
82+
83+
# Customisation ---------------------------------------------
84+
#
85+
# This space below is where custom yaml items (e.g. pinning
86+
# sandpaper and varnish versions) should live
87+
88+
varnish: intersect-training/varnish

fig/branches/branches.png

333 KB
Loading

fig/branches/checkout_branch.png

142 KB
Loading

fig/branches/commit_branch.png

122 KB
Loading

fig/branches/create_branch.png

98.1 KB
Loading

fig/branches/merge_into_branch.png

197 KB
Loading

fig/branches/merge_into_main.png

183 KB
Loading

0 commit comments

Comments
 (0)