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
- "What are repositories and how are they created?"
7
7
- "What do `add` and `commit` mean?"
8
8
- "How do I check the status of my repository?"
9
9
objectives:
10
-
- "create a git repository"
11
-
- "track changes to files using the git repository"
12
-
- "query the current status of the git repository"
10
+
- "create a Git repository"
11
+
- "track changes to files using the Git repository"
12
+
- "query the current status of the Git repository"
13
13
keypoints:
14
14
- "When you initialize a Git repository in a directory, Git starts tracking the changes you make inside that directory."
15
15
- "This tracking creates a history of the way the files have changed over time."
16
16
- "Git uses a two-step process to record changes to your files. Changes to files must first be added to the staging area, then committed to the Git repository."
17
17
---
18
18
19
-
### Using Git
19
+
### Setting up Git
20
20
21
-
One of the main barriers to getting started with git is the language. Although some of the language used in git is
22
-
fairly self-explanatory, other terms are not so clear. The best way to get to learn the language - which consists of a
23
-
number of verbs such as `add`, `commit` and `push` (preceded by the word 'git') - is by using it, which is what we will be doing during this
24
-
lesson. These commands will be explained as we proceed from setting up a new version-controlled project to publishing
25
-
our own website.
21
+
When we use Git on a new computer for the first time,
22
+
we need to configure a few things. The basic elements of a configuration for Git are:
23
+
24
+
* your name and email address,
25
+
* what your preferred text editor is,
26
+
* set the name of your default branch (branches are an important component of Git that we will cover later)
27
+
* and that you want to use these settings globally (i.e. for every project).
28
+
29
+
First, we will tell Git our user name and email. For this lesson, we will be interacting with [GitHub](https://github.com/) and so we want to use the same email address we used when we set up our GitHub account. If you are concerned about privacy, please review [GitHub’s instructions for keeping your email address private](https://help.github.com/articles/keeping-your-email-address-private/).
30
+
31
+
It is possible you may have already set up Git on your computer in the past, so let's start by checking if there are any existing configurations.
32
+
33
+
Open your shell terminal window and type:
34
+
35
+
~~~
36
+
$ git config --list
37
+
~~~
38
+
{: .language-bash}
39
+
40
+
On MacOS, without any configuration your output might look like this:
41
+
42
+
~~~
43
+
credential.helper=osxkeychain
44
+
~~~
45
+
{: .output}
46
+
47
+
On Windows, without any configuration your output might look like this:
Assuming you have not set up Git on your computer before, let's go ahead and add our information to our configuration now.
67
+
68
+
Please note: For this lesson, we will be interacting with [GitHub](https://github.com/) and so the email address used should be the same as the one used when setting up your GitHub account. If you are concerned about privacy, please review [GitHub’s instructions for keeping your email address private](https://help.github.com/articles/keeping-your-email-address-private/).
69
+
70
+
Type these two commands into your shell, replacing `Your Name` and the email address with your own:
If you enter the commands correctly, the shell will merely return a command prompt and no messages. To check your work, ask Git what your configuration is using the same command as above:
79
+
80
+
~~~
81
+
git config --list
82
+
~~~
83
+
{: .language-bash}
84
+
85
+
~~~
86
+
user.name=Your Name
87
+
user.email=yourname@librarian.la
88
+
~~~
89
+
{: .output}
90
+
91
+
Let's also set our default text editor. A text editor is necessary with some of your Git work and the default from Git is vim, which is a great tool, but not useful if you're not familiar with it.
92
+
Any text editor can be made default by adding the correct file path and command line options (see [GitHub help](https://help.github.com/articles/associating-text-editors-with-git/)).
93
+
However, the simplest `core.editor` values are `"notepad"` on Windows, `"nano -w"` on Mac, and `"nano -w"` on Linux.
94
+
95
+
For example:
96
+
97
+
~~~
98
+
$ git config --global core.editor "notepad"
99
+
~~~
100
+
{: .language-bash }
101
+
102
+
~~~
103
+
$ git config --global core.editor "nano -w"
104
+
~~~
105
+
{: .language-bash}
26
106
107
+
Lastly, we need to set the name of our default branch to `main.`
108
+
109
+
~~~
110
+
$ git config --global init.defaultBranch main
111
+
~~~
112
+
{: .language-bash }
113
+
114
+
The `init.defaultBranch` value configures git to set the default branch to `main` instead of `master`.
27
115
28
116
### Creating a repository
29
117
@@ -41,6 +129,17 @@ $ cd hello-world
41
129
~~~
42
130
{: .language-bash }
43
131
132
+
### Using Git
133
+
134
+
One of the main barriers to getting started with Git is the language. Although some of the language used in Git is
135
+
fairly self-explanatory, other terms are not so clear. The best way to get to learn the language - which consists of a
136
+
number of verbs such as `add`, `commit` and `push` (preceded by the word 'git') - is by using it, which is what we will be doing during this
137
+
lesson. These commands will be explained as we proceed from setting up a new version-controlled project to publishing
138
+
our own website.
139
+
140
+
On a command line interface, Git commands are written as `git verb options`,
141
+
where `verb` is what we actually want to do and `options` is additional optional information which may be needed for the `verb`. So let's get started with our setup.
142
+
44
143
We will now create an empty git repository to track changes to our project. To do this we will use the git **init** command,
0 commit comments