Skip to content

Commit 5a79c03

Browse files
committed
Add page on branching
1 parent db0de57 commit 5a79c03

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ minimal guide to get started.
2222
- [Handling merge conflicts](pages/merge_conflicts.html).
2323
- [Oops; that last commit message was wrong](pages/amend_commit_msg.html).
2424
- [Exploring the code and its history](pages/exploring_code.html).
25+
- [Branching and merging](pages/branching.html).
2526
- [Other (much more thorough) resources](pages/resources.html).
2627

28+
2729
I love git and github. I
2830
use both for keeping track of programming projects, papers, talks, and
2931
data analyses. And github has enabled me to

pages/branching.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
layout: page
3+
title: Branching and merging
4+
---
5+
6+
I touched on just a few things about git. Get yourself going with git and
7+
github and then start looking at some of the many
8+
[resources](resources.html).
9+
10+
In particular, pay attention to: [Branching](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging):
11+
Create a separate _branch_ to develop a feature (or work on a
12+
bug) without disturbing the _master_ branch. If it works out, you
13+
can merge it back into the master; if it doesn't, you can trash it.
14+
Branching is super easy, so for big projects, you should probably do it more
15+
often than not.
16+
17+
To create a branch called `new_feature`:
18+
19+
$ git branch new_feature
20+
21+
Then “check it out”:
22+
23+
$ git checkout new_feature
24+
25+
Make various modifications, and then add and commit.
26+
27+
To go back to the master branch, check it out:
28+
29+
$ git checkout master
30+
31+
To push the branch to github, use this:
32+
33+
$ git push origin new_feature
34+
35+
If you make changes to the master branch, you'll want to merge them
36+
into your exploratory one:
37+
38+
$ git checkout new_feature
39+
$ git merge master
40+
41+
If you're satisfied with your changes in the exploratory branch, merge
42+
them into the master:
43+
44+
$ git checkout master
45+
$ git merge new_feature
46+
47+
If you're done with the branch and want to delete it:
48+
49+
$ git branch -d new_feature
50+
51+
But if you pushed it to github, it will still exist there. This is
52+
how to delete the branch from github:
53+
54+
$ git push origin --delete new_feature
55+
56+
After pulling from github, use the following to get access to a branch
57+
that is only on github:
58+
59+
$ git checkout -b new_feature origin/new_feature
60+
61+
If you want to pull a particular branch from a collaborator's
62+
repository, do this:
63+
64+
$ git checkout new_feature
65+
$ git pull myfriend new_feature
66+
67+
One final point: note that
68+
[`git pull`](https://www.kernel.org/pub/software/scm/git/docs/git-pull.html)
69+
is really doing a
70+
[`git fetch`](https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html)
71+
followed by a
72+
[`git merge`](https://www.kernel.org/pub/software/scm/git/docs/git-merge.html).

0 commit comments

Comments
 (0)