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
Copy file name to clipboardExpand all lines: docs/chapters/chapter_04.md
+62-6Lines changed: 62 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ As discussed previously, there are a wide variety of hosting services. Here, onl
11
11
In this example, we will make a fresh repository on GitHub, make some changes from the browser, and clone a local copy so that we can work on it offline.
12
12
13
13
!!! info Note
14
-
If you already have a local repository, like we have done in the previous chapter, go to chapter 4.2.
14
+
Chapter 4.2 describes the variation if you already have a local repository (like we have done in the previous chapter).
15
15
16
16
### Create a repo on GitHub
17
17
@@ -55,7 +55,9 @@ Now there are several options:
55
55
56
56

57
57
58
-
- Otherwise, copy the line of link (with the button on the right). Go to your preferred IDE and clone the repo there. ===Screenshots!===
58
+
- Otherwise, copy the line of link (with the button on the right). Go to your preferred IDE and clone the repo there.
59
+
60
+

59
61
60
62
- If you work with commandlines, go to the parent folder where you want the new repo to be copied into, and then use the `git clone` command (replacing `<some-parent-folder>` and `<your-github-id>`):
61
63
@@ -68,16 +70,48 @@ Look inside the `learn-git` folder. You have the new repo cloned onto your compu
68
70
69
71
### Make changes locally and keep the remote updated
70
72
71
-
As you make new changes in this folder, you can make local commits just as you did in #3.6. As long as you are on a single branch, the only extra step to take to update the remote is "pushing". Here is an example:
73
+
As you make new changes in this folder, you can make local commits just as you did in #3.6.
74
+
75
+
!!! example "Exercise"
76
+
If you want to make an edit to the `README.md` file, what steps do you need to take to make the commit?
## 4.2 Setting up a new online repository for an existing local repository
77
97
78
98
Sometimes, we may have already written some code and created a local repository (like what we did in #3.6). Now we want to set up a remote repository and send our code to it, so that our local work is backed up online, and later be shared.
79
99
80
-
If you have followed through #4.1 as well, you will find this very familiar, except in some small details.
100
+
Here we use an example of `learn-git1` local repository with 2 files already commited.
101
+
102
+
### Publish with GitHub Desktop
103
+
104
+
If you use GitHub Desktop, the process is very easy. On the top banner, click the `Publish repository` button.
Then enter descriptions and click publish! All done.
109
+
110
+

111
+
112
+
### Without GitHub Desktop
113
+
114
+
The whole process is similar to Chapter 4.1, except in some small details.
81
115
82
116
### Create a repo on GitHub
83
117
@@ -87,11 +121,33 @@ First, log in to GitHub. Click the "+" and then "New repository" on the top righ
87
121
88
122
Then, give the new repo a meaningful name (probably sensible to be the same as your local folder name). To make life simple, do NOT initialize or add any files.
89
123
124
+

125
+
90
126
!!! example "Exercise"
91
127
What will happen if we initialized with, e.g. a README file?
92
128
93
129
??? success "Solution"
94
130
The remote repo on Github will have the README file, while our local repo does not. On the other hand, remember that our local repo has some existing codes that the remote does not have. Therefore, as soon as we try to link the two together, there will be a conflict.
95
131
96
-
Click the big green button at the bottom. Simple as that, we made a repository on GitHub.
132
+
Click the big green button at the bottom to create the repo.
133
+
134
+
### Connect to the local repo
135
+
136
+
Since the new online repository is completely empty, GitHub then shows you exactly how to connect to the local repository.
137
+
138
+
With your IDE, go to the version control tab and look for `Manage remote`.
139
+
140
+

141
+
142
+
Click `Add remote`, and paste in the URL to the GitHub repository page.
143
+
144
+

145
+
146
+
Now, do a *push*, which will update all the existing local commits to the remote.
147
+
148
+

149
+
150
+
That's all done! Have a look on the GitHub website. It's updated with the local changes!
0 commit comments