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
+71-3Lines changed: 71 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,22 @@ As discussed previously, there are a wide variety of hosting services. Here, onl
8
8
9
9
## 4.1 Starting a new single person repository
10
10
11
-
In this example, we will make a repository on GitHub and send our code to it, so that our local work is backed up online.
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
+
13
+
!!! info Note
14
+
If you already have a local repository, like we have done in the previous chapter, go to chapter 4.2.
15
+
16
+
### Create a repo on GitHub
12
17
13
18
First, log in to GitHub. Click the "+" and then "New repository" on the top right corner.
14
19
15
20

16
21
17
-
Then, give the new repo a meaningful name, and why not add a README file. Click the big green button at the bottom. Simple as that, we made a repository on GitHub.
22
+
Then, give the new repo a meaningful name (we will call it `learn-git`), and why not add a README file. Click the big green button at the bottom. Simple as that, we made a repository on GitHub.
18
23
19
-
ADD-IMAGE-IF-KNOW-WHAT-CODE-TO-USE
24
+

25
+
26
+
### Made changes from the browser
20
27
21
28
A very convenient feature of the online platforms like GitHub is that they allow us to make certain changes directly from the browser. For example, click into the `README.md` file, and then click on the pencil button on the right hand side:
22
29
@@ -27,3 +34,64 @@ Now we are in a text editor, and can make any changes we want to this file. Once
27
34
!!! info Note
28
35
Why the "Commit changes", but not a simple "Save"? Remember, Git keeps a history for everything. By editing on from the browser, we have essentially done "saving the file", "stage the file" and "commit changes" with one step!
Here you can input a commit message to describe what changes you have made. Then click the green "Commit changes" button again, and all done.
40
+
41
+
### Clone the repo to local computer
42
+
43
+
For day to day coding and scripting, we probably still want to work locally on our computers with IDEs or more sophisticated editors. To do this in our new repository, we first need to make a local clone on our computer. This is very easy to do.
44
+
45
+
Go to the homepage of our repo on Github. Click the green "< > Code" button at the top right corner above the file list. Click on the "SSH" tab.
46
+
47
+

48
+
49
+
!!! info Note
50
+
SSH is more secure than HTTPS. If you have set up your SSH keys successfully in the previous chapter, always try to use the SSH links.
51
+
52
+
Now there are several options:
53
+
54
+
- If you are working with GitHub Desktop, simply click on the link "Open with GitHub Desktop". You can choose where you want to keep the local copy.
55
+
56
+

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!===
59
+
60
+
- 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>`):
Look inside the `learn-git` folder. You have the new repo cloned onto your computer!
68
+
69
+
### Make changes locally and keep the remote updated
70
+
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:
72
+
73
+
===screenshots====
74
+
75
+
76
+
## 4.2 Setting up a new online repository for an existing local repository
77
+
78
+
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
+
80
+
If you have followed through #4.1 as well, you will find this very familiar, except in some small details.
81
+
82
+
### Create a repo on GitHub
83
+
84
+
First, log in to GitHub. Click the "+" and then "New repository" on the top right corner.
85
+
86
+

87
+
88
+
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
+
90
+
!!! example "Exercise"
91
+
What will happen if we initialized with, e.g. a README file?
92
+
93
+
??? success "Solution"
94
+
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
+
96
+
Click the big green button at the bottom. Simple as that, we made a repository on GitHub.
0 commit comments