Skip to content

Commit 30c08f1

Browse files
committed
Solo workflow tutorial
0 parents  commit 30c08f1

31 files changed

+278
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "themes/tutelage"]
2+
path = themes/tutelage
3+
url = [email protected]:naclomi/tutelage.git

archetypes/default.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "{{ replace .Name "-" " " | title }}"
3+
date: {{ .Date }}
4+
draft: true
5+
---

content/_index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
draft: false
3+
title: "Git Workflow Tutorials"
4+
---
5+
6+
This website hosts a series of tutorials explaining how to use Git, through the GUI tool Sublime Merge. TODO
7+
8+
# Modules
9+
TODO
10+
11+
# Credits and acknowledgement
12+
13+
These tutorials were written by [Naomi Alterman](https://staff.uw.edu/naomila) through her work at the [UW eScience Institute](https://escience.uw.edu).

content/backups/_index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
draft: false
3+
title: "Backing up repositories"
4+
---
5+
6+
# Introduction
7+
8+
Your repository doesn't have to _just_ live on your computer -- it's possible to back it up to the cloud (or another computer, or multiple locations on your current computer) and keep the timelines consistent across all of them.

content/solo/_index.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
---
2+
draft: false
3+
title: "Solo Git Workflow"
4+
---
5+
6+
# Introduction
7+
8+
TODO
9+
10+
# Setting up a lil journal
11+
12+
Make a new folder on desktop called 'my-journal'
13+
Open it and make a new text file in it called 'readme.txt'
14+
Open that in notepad/textedit
15+
16+
Type out some info about yourself, like this:
17+
18+
```bash
19+
Name: Naomi Alterman
20+
Favorite Food: Pizza
21+
Favorite Animal: Bunnies
22+
```
23+
24+
Save file.
25+
26+
But old versions will get lost!
27+
28+
# Turning our journal folder into a repository
29+
30+
Now, let's open Sublime Merge:
31+
32+
{{% aside %}}
33+
🔗 [url](url)
34+
{{% /aside %}}
35+
36+
yep
37+
38+
![](./img/first-open.png)
39+
40+
New Repository
41+
42+
Go to desktop, the `my-journal` folder. Click `Select Folder`
43+
44+
now our folder is a repository, and window looks like this:
45+
46+
![](./img/new-repo-view.png)
47+
48+
window layout:
49+
- timeline in center, showing ordered history of all commits.
50+
- file detail in right - given selected commit, can see what changed (the diff)
51+
- ignore left side for now
52+
53+
54+
# Making our first commit
55+
56+
57+
let's make our first commit, in which we'll mark the initial version of our user profile.
58+
59+
We'll start by **staging** the changes, which indicates to Git that we want to _include_ them in the next commit. Expand the list of "Untracked Files" (1), and then readme.txt (2). Note how this displays the contents of the file in green: these are the _changes_ in the file since the last commit, also called the *diff*. Since it's a new file, and this is our first commit, all of the file text is new and thus highlighted in green. To include this data in our commit, click the 'Stage' button (3):
60+
61+
![](./img/first-stage.png)
62+
63+
The summary tab will change, showing that instead of there being "untracked files", now there are "staged files". Write a commit message in the text box at the top of the summary tab indicating conceptually what these changes include (1), then click "Commit 1 file" (2):
64+
65+
![](./img/first-commit.png)
66+
67+
Our commit, and its message, will now appear in the center part of the window. If we select it with the mouse, we can see the changes to our files recorded at that point in time (in this case, the addition of our `readme.txt`):
68+
69+
![](./img/first-commit-timeline.png)
70+
71+
Notice the line in the summary labelled `Commit Hash`: the string of letters and numbers on this line, called a **hash**, serves as a unique name for this commit (that is, this set of changes to our files). Git tools (and git users) will often use commit hashes as "names" for specific points in the timeline. Insetad of including _all_ of the hash, it's often sufficient to just include 6 or 7 characters from the beginning (left side) of the hash. For example, the selected commit in the screenshot could be referred to as `commit 6725ed`.
72+
73+
# Using commits to record changes
74+
75+
Let's change our profile. Go over to your text editor and make a few changes:
76+
- Add a new line in the middle of the file and specify your favorite song.
77+
- Replace your favorite animal's name with its taxonomic name (you may have to google it)
78+
79+
80+
My profile now looks like this:
81+
82+
```bash
83+
Name: Naomi Alterman
84+
Favorite Song: "Under Pressure" by Queen
85+
Favorite Food: Pizza
86+
Favorite Animal: Oryctolagus cuniculus
87+
```
88+
89+
Save the file and go back to Sublime Merge. Click the "unstaged file" entry at the top of the timeline to see your changes to the file in the diff panel:
90+
91+
![](./img/change-diff.png)
92+
93+
Click 'Stage' next to readme.txt to accept the changes. Then type a commit message out and commit the changes. Now we'll have two commits in our history:
94+
95+
![](./img/two-commits.png)
96+
97+
Let's add another file. Make another file in your journal folder called `recipe.txt` and paste your favorite recipe into it:
98+
99+
![](./img/recipe-text.png)
100+
101+
Add a new line to `readme.txt` mentioning it:
102+
103+
```bash
104+
Name: Naomi Alterman
105+
Favorite Song: "Under Pressure" by Queen
106+
Favorite Food: Pizza
107+
Favorite Animal: Oryctolagus cuniculus
108+
Favorite Recipe: Oatmeal butterscotch cookies (see recipe.txt for details)
109+
```
110+
111+
Make sure to save all those files, and then return to Sublime Merge. You'll see the changes to your `readme.txt` file, but the brand new file is currently hidden. To add it to the repository, expand the "Untracked Files" section at the bottom:
112+
113+
![](./img/untracked-2.png)
114+
115+
Click the "Stage" button on both `readme.txt` and `recipe.txt` to include both of them in our next commit:
116+
117+
![](./img/stage-recipe.png)
118+
119+
Now type out a commit message, and make the commit!
120+
121+
![](./img/stage-both.png)
122+
123+
Now we have a journal folder containing our personal profile and our favorite recipe. We can click different commits in Sublime Merge's timeline view to see how those files changed over time:
124+
125+
![](./img/random_commit.png)
126+
127+
To view the difference between two commits that aren't next to each other in time, hold the control key and select the two commits you want to compare (TODO: command on mac?). Notice the `Diffing from` line in the summary, indicating the point in the timeline we're "comparing" against. Put another way: by selecting multiple commits, the diff view will show us all of the changes that happened between those points in the timeline:
128+
129+
![](./img/custom-diff.png)
130+
131+
# Time-travelling with check-outs
132+
133+
Sublime Merge will let us browse the diffs at various points in time, but what if we want to open previous versions of our files in other applications, like Photoshop or VSCode?
134+
135+
We can use Git to "time-travel" all of the files back to a previous point in time by *checking out* a previous commit. In general Git jargon, the term *check out* means to make the contents of a file or set of files reflect their contents at the time a given commit was made:
136+
- To "check out a commit" means to make all files in the repo reflect their contents at that commit's point in the timeline.
137+
- To "check out a file" usually means to return a file to its present-day contents
138+
139+
Anyway, let's check out a previous commit.
140+
141+
Right-click the first commit in our timeline and select "Checkout Commit":
142+
143+
![](./img/check-out-1.png)
144+
145+
Sublime Merge will likely display a warning message about a "detached head", and the timeline view will change to look something like this:
146+
147+
![](./img/detached-head.png)
148+
149+
There is a lot going on here! Some things worth noticing:
150+
151+
- The `HEAD` label on the "Initial Commit" entry. This label refers to the point in the timeline we currently are "visiting". Usually, `HEAD` points to the most recent commit and is hidden from the timeline view. Because we've moved back in time, the label now appears to indicate this.
152+
153+
- There is a dotted line running from "Initial commit" to the top of the list, in parallel with all the other commits we made. This is a visual indicator that if we make any changes to our files now, they represent a _completely different timeline_ than the one we made our previous commits on.
154+
155+
- There is no name for this brave new timeline, and hence HEAD is "detached". Any changes and commits we make will get lost the next time we return to the main timeline, since we have no name to refer to them with. There are _proper_ ways to make changes on an alternate timeline, but we won't discuss them in this workflow.
156+
157+
As a rule, we don't check out a previous commit to make changes. We check it out to _view_ the previous state of our work. We'll talk about how to "undo" things in a bit.
158+
159+
All that discussion aside, open your journal folder and take a look:
160+
161+
![](./img/old.png)
162+
163+
The `readme.txt` file reflects its contents from the beginning of our tutorial, and the `recipe.txt` file is completely missing! This is because, at the time of the checked-out commit, it didn't exist yet. Luckily it's not lost forever, though: it's stored safely in our repository's history (in this case, in commits that "will happen" in the "future", according to the main timeline).
164+
165+
Let's return to the present. In Sublime Merge, take a look at the left side of the window. The `Branches` list records all of the named timelines in our repository. Right-click `Main` and select `Checkout main`:
166+
167+
![](./img/branch-main.png)
168+
169+
The timeline view should return to normal:
170+
171+
![](./img/normal.png)
172+
173+
We've returned to the present. Take a look at your folder window, everything there should be back to normal too 😄.
174+
175+
# Undoing something from history
176+
177+
Let's say we made a mistaken change to our text in the past, and want to undo those changes. Git generally doesn't want us to alter the historical timeline. Instead, it'll have us make a _new_ commit that "undoes" the changes in the past we wish to remove. This is called a **revert**.
178+
179+
Let's say we want to _undo_ the contents of the second commit we made. That is, the commit that changed our favorite animal name to its taxonomic classification and listed our favorite song. We want to _keep_ our recipe around though -- we're just tired of scientific names we don't understand and old songs we don't want to hear anymore.
180+
181+
Right-click that second commit and choose "Revert":
182+
![](./img/revert-1.png)
183+
184+
Uh oh! You'll see a message about a failure, and some new stuff will appear in the summary tab:
185+
186+
![](./img/revert_issue.png)
187+
188+
What happened was called a *conflict*: Git couldn't figure out how to make the changes we requested (fixing the animal line) without also screwing up some of the changes that happened later on (adding the recipe line). This is a common error to encounter, and very worth our while to get experience dealing with!
189+
190+
Whenever we encounter a conflict, we need to open the file in a text editor and _fix_ the conflicted portions of it. Those portions are labelled with a specific notation:
191+
192+
```python
193+
<<<<<<< VERSION 1 LABEL
194+
version 1 of the conflicting text
195+
=======
196+
version 2 of the conflicting text
197+
>>>>>>> VERSION 2 LABEL
198+
```
199+
200+
Wherever these angle brackets `<<<<<<< ... >>>>>>>` appear, they indicate two different versions of the same section of text, separated by the `=======`. Git couldn't choose between them, so it wants us to replace this conflicting section, including the angle brackets `<<<<<<< ... >>>>>>>`, with the version _we_ want. Maybe this is the top version. Maybe it's the bottom. Maybe it's some clever combination of the two.
201+
202+
For the rever we're working on, we want to keep the `Favorite Animal` line from the _bottom_ version, and the `Favorite Recipe` line from the top version. So let's open `readme.txt` in our text editor and replace the `<<<<<<< ... >>>>>>>` brackets and everything between them with the lines we want to keep:
203+
204+
![](./img/conflict-fix.png)
205+
206+
Save the file and return to Sublime Merge. Click the "Stage" button on `readme.txt` to include our changes in the upcoming revert:
207+
208+
![](./img/revert-stage-fix.png)
209+
210+
Finally, click the "Complete" button:
211+
212+
![](./img/complete-revert.png)
213+
214+
Our timeline will now include a new commit which "undoes" those changes we wanted to erase:
215+
216+
![](./img/finished-revert.png)
217+
218+
Hooray!
219+
220+
221+
{{% aside %}}
222+
223+
**Git "resets"**
224+
225+
You might have noticed another option when right-clicking to _reset main_ to a given commit. This **edits** the timeline so that it stops at the commit we are resetting to, and any commits that happened afterwards get **deleted**. This means we're **actually erasing history**, which is a very dangerous thing to do! In rare occasions it's the right choice, but you should always ask someone with more Git experience before actually doing it.
226+
227+
{{% /aside %}}
228+
229+
# What next?
230+
231+
Your repository doesn't have to _just_ live on your computer -- it's possible to back it up to the cloud (or another computer, or multiple locations on your current computer) and keep the timelines consistent across all of them. We'll cover that in the next chapter.

content/solo/img/branch-main.png

78.2 KB
Loading

content/solo/img/change-diff.png

64.9 KB
Loading

content/solo/img/check-out-1.png

47.9 KB
Loading

content/solo/img/complete-revert.png

28.8 KB
Loading

content/solo/img/conflict-fix.png

40.3 KB
Loading

content/solo/img/custom-diff.png

94.2 KB
Loading

content/solo/img/detached-head.png

50.9 KB
Loading

content/solo/img/finished-revert.png

75.4 KB
Loading
59.7 KB
Loading

content/solo/img/first-commit.png

23.2 KB
Loading

content/solo/img/first-open.png

46.2 KB
Loading

content/solo/img/first-stage.png

66.7 KB
Loading

content/solo/img/new-repo-view.png

41.1 KB
Loading

content/solo/img/normal.png

91.2 KB
Loading

content/solo/img/old.png

21.5 KB
Loading

content/solo/img/random_commit.png

77.3 KB
Loading

content/solo/img/recipe-text.png

28.3 KB
Loading

content/solo/img/revert-1.png

46.5 KB
Loading

content/solo/img/revert-stage-fix.png

55.2 KB
Loading

content/solo/img/revert_issue.png

47.3 KB
Loading

content/solo/img/stage-both.png

26.4 KB
Loading

content/solo/img/stage-recipe.png

54.3 KB
Loading

content/solo/img/two-commits.png

43.9 KB
Loading

content/solo/img/untracked-2.png

57.4 KB
Loading

hugo.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
baseURL: https://uwescience.github.io/intro-git-tutorial
2+
languageCode: en-us
3+
title: Classic Git Workflows
4+
theme: "tutelage"
5+
6+
params:
7+
lineNoMinThreshold: 4
8+
markup:
9+
tableOfContents:
10+
startLevel: 0
11+
# endLevel: 5
12+
highlight:
13+
lineNos: true
14+
anchorLineNos: true
15+
goldmark:
16+
renderer:
17+
unsafe: true

themes/tutelage

Submodule tutelage added at 3c8f190

0 commit comments

Comments
 (0)