-
Notifications
You must be signed in to change notification settings - Fork 4
/
1.1-what_is_git.qmd
206 lines (140 loc) · 5.47 KB
/
1.1-what_is_git.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
---
title: "Intro to `git`"
subtitle: "Block 1.1: What is git?"
---
::: attribution
Background: https://unsplash.com/photos/842ofHC6MaI
:::
## What is git?
- Version Control System (VCS)
- Looks at the changes in your files
- Records all changes over time to give you a full history
- Similar to "track changes" in Microsoft Word / LibreOffice
::: {.fragment}
![Git only looks at and tracks the *changes* in a file](images/carpentries/play-changes.svg)
:::
## What is git? *Strengths* & Weaknesses
- Strengths 💪
- Very hard to lose files with git
- Great for collaboration
- Fast (like, really fast)
- History allows you to go back and understand changes or revert when there are problems
- Reproducibility
## What is git? Strengths & *Weaknesses*
- Weaknesses 😢
- Can be a bit complicated to use (esp. at first)
- History takes up file space (but only little)
- Struggles with binary (i.e. non-text) files
- Struggles with large files
- Not good for storing data!
- You do need to *explicitly* use it i.e. it doesn't just work in the background
## CLI vs. GUI?!
Git can be used via both a CLI and GUI.
:::: {.columns}
::: {.column width="50%"}
*Command Line Interface (CLI)*
- Also Console or Terminal
- Only text
- You type your command, press enter and receive back text
- *Very* flexible, but a bit unintuitive
:::
::: {.column width="50%"}
*Graphical User Interface (GUI)*
- Most applications nowadays
- Often asier to use
- Typically mainly controlled via your Mouse
- Buttons and other clickable elements
:::
::::
## CLI vs. GUI?!
:::: {.columns}
::: {.column width="50%"}
![An example of using git in a command line interface (CLI)](images/screenshots/terminal-empty.png)
:::
::: {.column width="50%"}
![An example of using git in SourceTree, a graphical user interface (GUI)](images/screenshots/sourcetree-test.png)
:::
::::
## CLI vs. GUI: `git`
- `git` itself is a CLI program
- But, many GUIs are available
- [Sourcetree](https://www.sourcetreeapp.com/)
- [Visual Studio Code](https://code.visualstudio.com/)*
- [Rstudio](https://posit.co/download/rstudio-desktop/)*
- [Github Desktop](https://github.com/apps/desktop)
- ... (full list: <https://git-scm.com/downloads/guis>)
::: {.fragment}
*: These programs have a different main purpose, but also offer the option of using git via their GUI.
:::
## Using the `git` CLI
- We will first use git via its CLI (i.e. in the Terminal).
- On windows, open Git Bash (start menu -> Git Bash).
- On MacOS, open the Terminal app.
- On Linux, open your distribution’s (or any other) terminal emulator.
- Let's do this together now!
## Using the `git` cheatsheet to follow along
- There are many existing cheatsheets out there with the most important git commands
- In this course we will be using the one from [GitHub Education](resources/git-cheat-sheet-education.pdf) to help you navigate the course
## Let's Set Things Up: `git config` ⚙️
Run the following commands in your terminal to correctly configure git on your computer.
```bash
# Add your name
git config --global user.name "Your Name"
# Add your email address
git config --global user.email "your.email@kit.edu"
# Use modern main branch name
git config --global init.defaultbranch main
```
## Let's Set Things Up: `git config` ⚙️
For Linux/Mac:
```bash
git config --global core.autocrlf input
```
For Windows:
```bash
git config --global core.autocrlf true
```
Why? Windows saves linebreaks (enter) differently then Linux/Mac does 🤷♂️
# Getting started with git (for real) {background-color="black" background-opacity="0.7" background-image="images/backgrounds/rolling-up-sleeves.gif"}
::: attribution
Background: Warnerbros, via [Digital Spy](https://www.digitalspy.com/movies/a823040/harry-potters-jason-isaacs-says-co-star-alan-rickman-stole-from-gringotts-bank/)
:::
## See what's happening: `git status`
A project in git is called a **repository** (or **repo** for short) and it always corresponds to a directory on your machine.
To see the current status of a git repository you can run the `status` command.
```bash
git status
```
## See what's happening: `git status`
```bash
git status
# fatal: not a git repository (or any of the parent directories): .git
```
We get an error here, because you first need to *initialize* a git repository.
## Initializing a repository: `git init`
Before we can use git in a project we first have to initialize it in the directory of the project. This is done via the `init` command.
```bash
git init
# Initialized empty Git repository in /Users/jan/Dev/temp/test/.git/
git status
# On branch main
# No commits yet
# nothing to commit (create/copy files and use "git add" to track)
```
With `git init` we turn the *directory* into a *repository*.
## Practical: init {background-color="black"}
1. Identify the filepath of the **directory** you created earlier.
2. Open the Terminal (or Git Bash on Windows) in VS Code
3. Use `git init` to initialize a new repository there
4. Keep VS Code open in this directory for later
## Downloading a repository: `git clone`
Alternatively, we can download a repository from the internet using the `clone` command. This will create a new repository on our machine and fill it with the remote repository's contents.
```bash
git clone https://github.com/open-teaching/git-murder-mystery.git
```
## *End of Section* 🎉 {background-color="black"}
:::{.r-fit-text}
Any Questions?
:::
[[🏡 Back to Overview]](./index.html)
[[⏩️ Next Section]](./1.2-tracking_changes.html)