You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The important thing to remember in this level is to commit your changes as you make them.
2
+
3
+
In general with Git, things go kinda like this:
4
+
1. Make changes
5
+
2. Tell Git about those changes
6
+
3. Commit those changes
7
+
4. Push your changes to a remote branch
8
+
9
+
Git Gud hasn't covered remote branches yet, but they're how most people share their code with other people.
10
+
11
+
>>>
12
+
13
+
This makes sense if you think about it backwards.
14
+
4. When sharing your code, you may only want to share some of the files you're working on
15
+
3. You need some way to store a version of your code - that's what a commit is
16
+
2. For Git to know which version of the code to track, you need to tell it
17
+
1. Before Git can track any changes, you obviously need to make the changes
18
+
19
+
>>>
20
+
21
+
To help understand this, let's break down each step of the process:
22
+
1. Add a file <-- Let's break the first two down first
23
+
2. Add another file <-- Let's break the first two down first
24
+
3. Modify both files
25
+
4. Remove the first file
26
+
5. Move the second file
27
+
28
+
>>>
29
+
30
+
The first two steps are pretty simple. They're just the first two levels in this skill that you've already completed.
31
+
32
+
Recall back to what you did:
33
+
1. You created a file
34
+
2. You "git add"-ed the file
35
+
3. You "git commit"-ed the file
36
+
37
+
You did this twice. In the end, you created two files and ended up with two commits.
38
+
39
+
>>>
40
+
41
+
If you were paying attention to "git gud status", you might have noticed something:
42
+
The fist commit only knew about the first file, but the second commit knew about both files.
43
+
44
+
If you were also paying attention to "git status", you might have noticed something else:
45
+
The "staging area", which is shown when running "git status", only showed you the newly created file.
46
+
47
+
Why is that?
48
+
49
+
>>>
50
+
51
+
As soon as you make a commit, Git is ready to start tracking another commit. Git knows that in a code base with multiple files, most of the time you'll only be changing a few of them at a time.
52
+
53
+
Whenever you're looking at "git status", you're looking at the changes you've made. Git still knows about all the other files and will help you figure out what you want to include the next time you commit.
54
+
55
+
>>>
56
+
57
+
So, looking back, when you first created a file, it was the only file in the working directory, and it showed up when you ran "git status". You added the file, and it still showed up when you ran "git status", but after you committed it, the file no longer appeared when you ran "git status".
58
+
59
+
When you created the second file, it showed up when you ran "git status" too, and then you added it and committed it, but that time, the first file was still in the working directory. The first file doesn't show up when you run "git status", but Git still knows about it.
60
+
61
+
>>>
62
+
63
+
Now, let's look at the rest of the steps:
64
+
1. Add a file
65
+
2. Add another file
66
+
3. Modify both files <-- Let's look at these
67
+
4. Remove the first file <-- Let's look at these
68
+
5. Move the second file <-- Let's look at these
69
+
70
+
You're still making changes, but this time, instead of creating a new file, you're doing all the other things you can do with files - Updating, deleting and removing
71
+
72
+
>>>
73
+
74
+
So now, we can learn about a few more commands
75
+
You can use "git add" when you want to tell Git to "add" new changes to existing files
76
+
You can use "git rm" when you want to tell Git to "remove" files
77
+
You can use "git mv" when you want to tell Git to "move" or rename files
78
+
79
+
Finally, Git only stores versions of a repo. It doesn't actually store changes, but Git can tell if two files contents are the same. In Git's view, removing a file and then adding a file with the same contents is the same thing as moving it or renaming the file.
0 commit comments