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: version-control/command-line/tutorial.md
+24-21Lines changed: 24 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@ layout: page
3
3
title: Introduction to the git command line
4
4
---
5
5
6
-
## Introduction to the git command line
6
+
## Introduction to the Git command line
7
7
8
8
**PREREQUISITE:** Basic understanding of the command line.
9
9
10
10
Git is an easy to share and collaborate tool that keeps our code tracked and safe.
11
11
With the following examples we understand how to deal with the daily usage of the tool.
12
12
13
13
## Before you begin
14
-
Install command line git for [OS X](http://code.google.com/p/git-osx-installer) or [Windows](http://msysgit.github.com/) and open your terminal. If you are on linux you should already have git installed.
14
+
Install command line git for your operating system ([OS X](http://code.google.com/p/git-osx-installer), [Windows](http://msysgit.github.com/)or [Linux](http://git-scm.com/download/linux)) and open your terminal / command prompt.
15
15
16
16
Create a directory where you will be storing all your projects. You can call it `code` or `projects`.
17
17
@@ -41,17 +41,19 @@ $ git init
41
41
### Create a file
42
42
43
43
```bash
44
-
$ echo"Learning git"> index.html
44
+
$ echo"<h1>Learning git</h1>"> index.html
45
45
```
46
46
47
-
> The above command will output `<h1>Learning git</h1>` and store it in index.html. Open up the file and have a look.
47
+
> The above command will output `<h1>Learning git</h1>` and store it in `index.html`. Open up the file and have a look.
48
48
49
49
### Check the git repository status.
50
50
51
51
```bash
52
52
$ git status
53
53
```
54
54
55
+
> The above command will tell you what files in the current directory have been changed, what files have not yet been added to the git repository and so on.
56
+
55
57
### Add your file on the repository and commit your changes.
56
58
57
59
```bash
@@ -60,15 +62,15 @@ $ git status
60
62
$ git commit -m 'this is my first command-line commit!'
61
63
```
62
64
63
-
> . will add all the files in the current directory and subdirectories. You should only use it when initialising your repository, or you can specify the file name.
65
+
> `.` will add all the files in the current directory and subdirectories. You should only use it when initialising your repository. Rest of the time you can specify the file names to be added.
64
66
65
67
### Check the git commit history.
66
68
67
69
```bash
68
70
$ git log
69
71
```
70
72
71
-
### Transferring project repository to online service
73
+
### Transferring project repository to an online service
72
74
73
75
First you need to create an account to the service of your choice ([GitHub](http://github.com/join), [GitLab](http://gitlab.com)). Then, create a new project (or repository).
74
76
@@ -82,9 +84,9 @@ $ git push -u origin master
82
84
83
85
#### What is `remote`
84
86
85
-
`remote` git all the remote repositories you have configured. You could have the same repository stored in many resources like GitHub and GitLab or Heroku.
87
+
`remote`is simply the URL of your repository in any online repository hosting services. The `git remote` lists all the remote repositories you have configured. You could have the same repository stored in many places like GitHub and GitLab or Heroku and in such cases you will have a remote configured for each of the remote repository you have.
86
88
87
-
The structure of the command is `git remote <add|remove> <name of remote> <url of remote>`
89
+
The structure of the command to add a new `remote`is `git remote <add|remove> <name of remote> <url of remote>`.
88
90
89
91
#### List all your remote repositories
90
92
@@ -103,7 +105,7 @@ Username for 'https://github.com': <your username>
> When you are working with remote repo is important to sync your local repo before any commit, merge or push.
108
+
> When you are working with a remote repo it is important to sync your local repo before doing any commit, merge or push.
107
109
108
110
### Syncing the remote copy with your local copy
109
111
@@ -114,7 +116,7 @@ $ git log
114
116
115
117
# Example 2: Working with a remote service
116
118
117
-
Update the index.html file and then commit and push the changes
119
+
Update the `index.html` file and then commit and push the changes
118
120
119
121
```html
120
122
<html>
@@ -128,7 +130,7 @@ Update the index.html file and then commit and push the changes
128
130
<dt>Initialise a git repository</dt>
129
131
<dd>git init</dd>
130
132
<dt>Add files to git</dt>
131
-
<dd>git add <filename></dd>
133
+
<dd>git add filename</dd>
132
134
</dl>
133
135
</body>
134
136
</html>
@@ -161,7 +163,7 @@ $ git log
161
163
162
164
# Example 3: Verifying changes before any commit
163
165
164
-
Edit index.html
166
+
Update `index.html`
165
167
166
168
167
169
```html
@@ -194,7 +196,7 @@ $ git diff
194
196
The -/+ indications you can see mean
195
197
196
198
**-** indicates lines removed from the code.
197
-
199
+
198
200
**+** indicates lines added to the code.
199
201
200
202
```bash
@@ -230,7 +232,7 @@ Edit the index.html file and then check the changes.
230
232
$ echo"oh no!"> index.html
231
233
```
232
234
233
-
> Have a look at the file using `git diff`
235
+
> Have a look at changes to the file using `git diff`
234
236
235
237
### Check the status of the repository
236
238
@@ -250,7 +252,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
250
252
### To discard the changes checkout the file
251
253
252
254
```bash
253
-
$ git checkout -- index.html
255
+
$ git checkout index.html
254
256
```
255
257
256
258
Don't forget to verify the changes
@@ -268,7 +270,7 @@ Repeat the steps below to change and commit a file
268
270
$ echo"oh not again"> index.html
269
271
$ git diff
270
272
$ git add index.html
271
-
$ git commit -am'Oops, I just deleted my list'
273
+
$ git commit -m'Oops, I just deleted my list'
272
274
```
273
275
274
276
> Can you explain the commands you just used?
@@ -304,7 +306,7 @@ Unstaged changes after reset:
304
306
M index.html
305
307
```
306
308
307
-
> The caret (^) after HEAD moves head back through commits. HEAD^ is short for HEAD^1 and in the same way you can apply HEAD^2 to go back two commit ago.
309
+
> The caret (^) after HEAD moves head back through commits. HEAD^ is short for HEAD^1 and in the same way you can apply HEAD^2 to go back two commits ago.
308
310
309
311
### Check the log again
310
312
@@ -339,7 +341,9 @@ $ git status
339
341
$ git log
340
342
```
341
343
342
-
> What does git push do?
344
+
> `git commit -am 'commit message` is short form for `git add .` followed by `git commit -m 'message'`.
345
+
346
+
> What does `git push` do?
343
347
344
348
### Reverting a commit
345
349
@@ -378,8 +382,7 @@ git push origin master
378
382
379
383
# Extras
380
384
381
-
If you are on OS X, check the following resources
382
-
385
+
Following are some good resources to to help you set up git.
383
386
https://help.github.com/articles/set-up-git
384
387
385
388
## Configuring your git environment
@@ -430,7 +433,7 @@ To apply this you need to create a .gitignore file in your root path. There you
430
433
> Do you know what these files are? You normally wouldn't want to commit logs or packages.
431
434
432
435
433
-
### Pimping your log history
436
+
### Pimping your log historyr
434
437
435
438
In your aliases add this as an alias for viewing git logs
0 commit comments