Skip to content

Commit fabce23

Browse files
committed
updated git workshop
1 parent 1a14776 commit fabce23

File tree

1 file changed

+92
-33
lines changed

1 file changed

+92
-33
lines changed

git.markdown

+92-33
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ keep track of your work. do this with `git init`
3232

3333
---
3434

35-
# key git commands
36-
37-
https://www.youtube.com/watch?v=u2rZLVWOWvs
38-
39-
---
40-
4135
# sample workflow
4236

4337
- `mkdir` for your new project
@@ -86,28 +80,72 @@ to see what one file looked like at a particular commit, do:
8680

8781
---
8882

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+
8992
# going back to a previous commit
9093

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
92124

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".
94132

95133
---
96134

97135
# github
98136

99-
https://www.youtube.com/watch?v=3cMP4oBKO34
137+
website that hosts git repos.
100138

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

103142
---
104143

105144
# starting a new github repo
106145

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

148+
- go to github.com.
111149
- on github: click the "new repository" button NOTE: do not
112150
make a README.
113151
- 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.
120158
now, when you go to your repo on github, it should have the
121159
contents of your last commit.
122160

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`
124168

125169
---
126170

@@ -135,36 +179,39 @@ directly to them.
135179
- check that everything has copied with `ls`
136180
- make whatever changes you want
137181
- `git status`
138-
- `git commit -am "adding xyz"` (make a commit on your local
139-
machine)
182+
- `git commit -am "adding xyz"` (commit locally)
140183
- `git push origin master` (push your changes back up to
141184
github)
142185

143186
---
144187

145188
# collaborating on existing github projects (no push access)
146189

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

152195
- 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
154197
your local machine).
155198
- on github, go to your own fork of the repo and find the
156199
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
159202
- 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
161209
- `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
165212
to your fork on github)
166213
- 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
168215
click "make a pull request"
169216

170217
---
@@ -173,20 +220,32 @@ branch.
173220

174221
each time you return to working on your local copy of a
175222
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.
177224

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
180226
idea to fork and work on your own branch of an existing
181227
project.
182228

183229
---
184230

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+
185245
# homework
186246

187247
Your homework is to do the git-it workshop on nodeschool:
188248

189249
http://nodeschool.io/#gitit
190250

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

Comments
 (0)