@@ -32,12 +32,6 @@ keep track of your work. do this with `git init`
32
32
33
33
---
34
34
35
- # key git commands
36
-
37
- https://www.youtube.com/watch?v=u2rZLVWOWvs
38
-
39
- ---
40
-
41
35
# sample workflow
42
36
43
37
- ` mkdir ` for your new project
@@ -86,28 +80,72 @@ to see what one file looked like at a particular commit, do:
86
80
87
81
---
88
82
83
+ # discard uncommitted changes
84
+
85
+ ` git stash `
86
+
87
+ gets rid of whatever uncommitted changes you have and
88
+ returns you to the state of your most recent commit.
89
+
90
+ ---
91
+
89
92
# going back to a previous commit
90
93
91
- ` git checkout `
94
+ ` git checkout -b branchname hashnumber `
95
+
96
+ checkout a previous commit to a new branch.
97
+
98
+ ---
99
+
100
+ # working with branches
101
+
102
+ ## make a new branch & switch to it
103
+
104
+ - ` git branch dev ` make a new branch named "dev"
105
+ - ` git checkout dev ` switch to branch "dev"
106
+
107
+
108
+ ` git branch ` see what branch you're on and what branches are
109
+ available.
110
+
111
+ ` git branch -d dev ` delete branch "dev"
112
+
113
+ when making a new branch, default behavior copies from
114
+ your current commit on your current branch.
115
+
116
+ a common use of branches: a "master" branch with a working version
117
+ of the project and a "dev" branch with active development.
118
+ when "dev" is ready for "production", it gets merged into
119
+ "master."
120
+
121
+ ---
122
+
123
+ # local vs remote
92
124
93
- checkout previous commits and make new branches!
125
+ we have been working on our "local" machine.
126
+
127
+ but it's common to also have a copy on a "remote" machine or
128
+ service (like github.com).
129
+
130
+ the rest of this presentation will mostly use "github", but
131
+ please note that this is just one example of a "remote".
94
132
95
133
---
96
134
97
135
# github
98
136
99
- https://www.youtube.com/watch?v=3cMP4oBKO34
137
+ website that hosts git repos.
100
138
101
- (addendum: i prefer ` git push origin master ` )
139
+ github repos live on github.com. you can have a million
140
+ projects in local git repos and zero activity on github.
102
141
103
142
---
104
143
105
144
# starting a new github repo
106
145
107
- github repos live on github.com. you can have a million
108
- projects in local git repos and zero activity on github. to
109
- put your local repo online, first go to github.com.
146
+ we will now put our local repo on github.com.
110
147
148
+ - go to github.com.
111
149
- on github: click the "new repository" button NOTE: do not
112
150
make a README.
113
151
- on github: once your new repo is ready, the site will show
@@ -120,7 +158,13 @@ put your local repo online, first go to github.com.
120
158
now, when you go to your repo on github, it should have the
121
159
contents of your last commit.
122
160
123
- ` git remote -v `
161
+ ---
162
+
163
+ # some github tips
164
+
165
+ - what remote repo is my local repo associated with? ` git remote -v `
166
+
167
+ - different branches can live on your remote: ` git push origin dev `
124
168
125
169
---
126
170
@@ -135,36 +179,39 @@ directly to them.
135
179
- check that everything has copied with ` ls `
136
180
- make whatever changes you want
137
181
- ` git status `
138
- - ` git commit -am "adding xyz" ` (make a commit on your local
139
- machine)
182
+ - ` git commit -am "adding xyz" ` (commit locally)
140
183
- ` git push origin master ` (push your changes back up to
141
184
github)
142
185
143
186
---
144
187
145
188
# collaborating on existing github projects (no push access)
146
189
147
- for existing github projects that you'd like to work on but
148
- that you don't have push access to, or where you'd like your
149
- own github repo to play around in before pushing to the main
150
- branch .
190
+ you may want to work with existing projects that you don't
191
+ have push access for.
192
+
193
+ to do this, we will "fork" the existing project .
151
194
152
195
- on github, fork the repo you want to work with. (this will
153
- give you your own copy of the repo on github, but not on
196
+ make a copy under your own github account , but not on
154
197
your local machine).
155
198
- on github, go to your own fork of the repo and find the
156
199
git url to clone the repo.
157
- - in terminal: ` git clone xyz.git ` (this pulls your forked
158
- copy to your local machine)
200
+ - in terminal: ` git clone xyz.git ` pulls your forked
201
+ copy to your local machine
159
202
- check that everything has copied with ` ls `
160
- - make whatever changes you want
203
+
204
+ ---
205
+
206
+ # collaborating on existing github projects (no push access) part 2
207
+
208
+ - make changes
161
209
- ` git status `
162
- - ` git commit -am "adding xyz" ` (this makes a commit on your
163
- local machine)
164
- - ` git push origin master ` (this pushes your changes back up
210
+ - ` git commit -am "adding xyz" ` (commit locally)
211
+ - ` git push origin master ` (push your changes back up
165
212
to your fork on github)
166
213
- to ask that your changes get merged back into the main
167
- branch, go to the main repo (not your fork) on github and
214
+ branch, go to the shared repo (not your fork) on github and
168
215
click "make a pull request"
169
216
170
217
---
@@ -173,20 +220,32 @@ branch.
173
220
174
221
each time you return to working on your local copy of a
175
222
shared github repo, do ` git pull origin master ` to make sure
176
- that you have the most up to date version of the repo.
223
+ that you have the most up-to- date version of the shared repo.
177
224
178
- many existing open source projects have code review before
179
- your pull request can be merged. this is why it's a good
225
+ your pull request may not get merged. this is why it's a good
180
226
idea to fork and work on your own branch of an existing
181
227
project.
182
228
183
229
---
184
230
231
+ # further learning
232
+
233
+ excellent, short videos that take you through the basics of
234
+ using git:
235
+
236
+ https://www.youtube.com/watch?v=u2rZLVWOWvs
237
+ https://www.youtube.com/watch?v=3cMP4oBKO34
238
+
239
+ this workshop and many others are at:
240
+
241
+ http://cyber.wizard.institute
242
+
243
+ ---
244
+
185
245
# homework
186
246
187
247
Your homework is to do the git-it workshop on nodeschool:
188
248
189
249
http://nodeschool.io/#gitit
190
250
191
- and to submit a pull request to a project with a useful fix
192
- or addition.
251
+ and to start keeping track of at least one project with git.
0 commit comments