-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path3.2-synching_changes.qmd
82 lines (59 loc) · 2.42 KB
/
3.2-synching_changes.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: "Intro to `git`"
subtitle: "Block 3.2: Synchronizing Changes"
---
## Syncing Changes: Overview
You first `pull` the latest changes from the remote and then `push` your own changes
![](images/drawings/pull-push.png)
## Getting Changes: `git pull`
- You can retrieve the latest changes from github by running `git pull`
- This *fetches* the latest changes and *merges* them into your current branch
- Typically your local branch is set up to *track* a remote branch with the same name (the `upstream`)
- If not, you get a warning from git
::: {.fragment}
```bash
# Pull from the tracked remote branch
git pull
# Pull from a specific branch
git pull <remote> <branch>
```
:::
## Getting Changes: `git pull`
- This *fetches* the latest changes and *merges* them into your current branch
- `git pull` really does *two* things here
- You can also run `git fetch` to fetch the latest changes and then `git merge <remote>/branch` to merge them
- `git fetch` will always fetch the latest changes without doing anything with them (which can be useful)
## Pushing Your Changes: `git push`
- You can send *your* changes to github by running `git push`
- This only works if there are no new changes at the remote
- If there have been changes since your last `pull` you need to `pull` again
::: {.fragment}
```bash
# Push to the tracked remote branch
git push
# Push a branch to the remote for the first time
# -u is short for --set-upstream
git push -u <remote> <branch>
```
:::
# Demo: Creating a new repository, pulling, pushing {data-visibility="hidden"}
# Questions?
## Practical: Adding your own repository to Github {background-color="black"}
1. Create a new repository on GitHub with the name `git-intro-example`
- Make sure NOT to add a README or any other file when creating it
2. In the example git repository we've been working in so far, add the just created GitHub repo as a remote
- `git remote add origin <URL>`
3. Push you changes so far to GitHub
- `git push -u origin main`
## Optional Practical: Collaboration {background-color="black"}
1. Form pairs
2. One person adds the other to their `git-intro-example` repository
- Via the GitHub UI (write privileges)
3. Each, add a new entry to the `library.txt`
4. Try to provoke a merge conflict
## *End of Section* 🎉 {background-color="black"}
:::{.r-fit-text}
Any Questions?
:::
[[🏡 Back to Overview]](./index.html)
[[⏩️ Next Section]](./3.3-markdown.html)