Skip to content

Commit 5da4b8e

Browse files
committed
More Ch4.
4.1 needs any example push; 4.2 need the matching folder as 3.6
1 parent 52127fb commit 5da4b8e

5 files changed

Lines changed: 71 additions & 3 deletions

File tree

docs/chapters/chapter_04.md

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ As discussed previously, there are a wide variety of hosting services. Here, onl
88

99
## 4.1 Starting a new single person repository
1010

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
1217

1318
First, log in to GitHub. Click the "+" and then "New repository" on the top right corner.
1419

1520
![Create new repo](images/add-new-repo.png)
1621

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.
1823

19-
ADD-IMAGE-IF-KNOW-WHAT-CODE-TO-USE
24+
![Create repo](images/create-repo.png)
25+
26+
### Made changes from the browser
2027

2128
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:
2229

@@ -27,3 +34,64 @@ Now we are in a text editor, and can make any changes we want to this file. Once
2734
!!! info Note
2835
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!
2936

37+
![Commit change online](images/commit-change-online.png)
38+
39+
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+
![Clone repo](images/clone-repo.png)
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+
![Clone GHD](images/clone-repo-ghd.png)
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>`):
61+
62+
```bash
63+
cd <some-parent-folder>
64+
git clone git@github.com:<your-github-id>/learn-git.git
65+
```
66+
67+
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+
![Create new repo](images/add-new-repo.png)
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.
97+
71.1 KB
Loading
70.3 KB
Loading
89.3 KB
Loading
256 KB
Loading

0 commit comments

Comments
 (0)