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: book/03-git-branching/sections/basic-branching-and-merging.asc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,15 +106,15 @@ Fast-forward
106
106
107
107
You'll notice the phrase ``fast-forward'' in that merge.
108
108
Because the commit `C4` pointed to by the branch `hotfix` you merged in was directly ahead of the commit `C2` you're on, Git simply moves the pointer forward.
109
-
To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit's history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a ``fast-forward.''
109
+
To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit's history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together -- this is called a ``fast-forward.''
110
110
111
111
Your change is now in the snapshot of the commit pointed to by the `master` branch, and you can deploy the fix.
112
112
113
113
.`master` is fast-forwarded to `hotfix`
114
114
image::images/basic-branching-5.png[`master` is fast-forwarded to `hotfix`.]
115
115
116
116
After your super-important fix is deployed, you're ready to switch back to the work you were doing before you were interrupted.
117
-
However, first you'll delete the `hotfix` branch, because you no longer need it – the `master` branch points at the same place.
117
+
However, first you'll delete the `hotfix` branch, because you no longer need it -- the `master` branch points at the same place.
118
118
You can delete it with the `-d` option to `git branch`:
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/rebasing.asc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,9 +52,9 @@ Now, the snapshot pointed to by `C4'` is exactly the same as the one that was po
52
52
There is no difference in the end product of the integration, but rebasing makes for a cleaner history.
53
53
If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.
54
54
55
-
Often, you'll do this to make sure your commits apply cleanly on a remote branch – perhaps in a project to which you're trying to contribute but that you don't maintain.
55
+
Often, you'll do this to make sure your commits apply cleanly on a remote branch -- perhaps in a project to which you're trying to contribute but that you don't maintain.
56
56
In this case, you'd do your work in a branch and then rebase your work onto `origin/master` when you were ready to submit your patches to the main project.
57
-
That way, the maintainer doesn't have to do any integration work – just a fast-forward or a clean apply.
57
+
That way, the maintainer doesn't have to do any integration work -- just a fast-forward or a clean apply.
58
58
59
59
Note that the snapshot pointed to by the final commit you end up with, whether it's the last of the rebased commits for a rebase or the final merge commit after a merge, is the same snapshot – it's only the history that is different.
60
60
Rebasing replays changes from one line of work onto another in the order they were introduced, whereas merging takes the endpoints and merges them together.
@@ -98,7 +98,7 @@ $ git merge client
98
98
image::images/interesting-rebase-3.png[Fast-forwarding your master branch to include the client branch changes.]
99
99
100
100
Let's say you decide to pull in your server branch as well.
101
-
You can rebase the server branch onto the `master` branch without having to check it out first by running `git rebase <basebranch> <topicbranch>` – which checks out the topic branch (in this case, `server`) for you and replays it onto the base branch (`master`):
101
+
You can rebase the server branch onto the `master` branch without having to check it out first by running `git rebase <basebranch> <topicbranch>` -- which checks out the topic branch (in this case, `server`) for you and replays it onto the base branch (`master`):
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/remote-branches.asc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ image::images/remote-branches-5.png[Remote tracking branch for `teamone/master`.
61
61
62
62
(((pushing)))
63
63
When you want to share a branch with the world, you need to push it up to a remote that you have write access to.
64
-
Your local branches aren't automatically synchronized to the remotes you write to – you have to explicitly push the branches you want to share.
64
+
Your local branches aren't automatically synchronized to the remotes you write to -- you have to explicitly push the branches you want to share.
65
65
That way, you can use private branches for work you don't want to share, and push up only the topic branches you want to collaborate on.
66
66
67
67
If you have a branch named `serverfix` that you want to work on with others, you can push it up the same way you pushed your first branch.
@@ -82,7 +82,7 @@ To https://github.com/schacon/simplegit
82
82
This is a bit of a shortcut.
83
83
Git automatically expands the `serverfix` branchname out to `refs/heads/serverfix:refs/heads/serverfix`, which means, ``Take my serverfix local branch and push it to update the remote's serverfix branch.''
84
84
We'll go over the `refs/heads/` part in detail in <<_git_internals>>, but you can generally leave it off.
85
-
You can also do `git push origin serverfix:serverfix`, which does the same thing – it says, ``Take my serverfix and make it the remote's serverfix.''
85
+
You can also do `git push origin serverfix:serverfix`, which does the same thing -- it says, ``Take my serverfix and make it the remote's serverfix.''
86
86
You can use this format to push a local branch into a remote branch that is named differently.
87
87
If you didn't want it to be called `serverfix` on the remote, you could instead run `git push origin serverfix:awesomebranch` to push your local `serverfix` branch to the `awesomebranch` branch on the remote project.
88
88
@@ -112,7 +112,7 @@ From https://github.com/schacon/simplegit
112
112
----
113
113
114
114
It's important to note that when you do a fetch that brings down new remote-tracking branches, you don't automatically have local, editable copies of them.
115
-
In other words, in this case, you don't have a new `serverfix` branch – you only have an `origin/serverfix` pointer that you can't modify.
115
+
In other words, in this case, you don't have a new `serverfix` branch -- you only have an `origin/serverfix` pointer that you can't modify.
116
116
117
117
To merge this work into your current working branch, you can run `git merge origin/serverfix`.
118
118
If you want your own `serverfix` branch that you can work on, you can base it off your remote-tracking branch:
@@ -135,7 +135,7 @@ Tracking branches are local branches that have a direct relationship to a remote
135
135
If you're on a tracking branch and type `git pull`, Git automatically knows which server to fetch from and branch to merge into.
136
136
137
137
When you clone a repository, it generally automatically creates a `master` branch that tracks `origin/master`.
138
-
However, you can set up other tracking branches if you wish – ones that track branches on other remotes, or don't track the `master` branch.
138
+
However, you can set up other tracking branches if you wish -- ones that track branches on other remotes, or don't track the `master` branch.
139
139
The simple case is the example you just saw, running `git checkout -b <branch> <remote>/<branch>`.
140
140
This is a common enough operation that Git provides the `--track` shorthand:
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/workflows.asc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ In this section, we'll cover some common workflows that this lightweight branchi
9
9
Because Git uses a simple three-way merge, merging from one branch into another multiple times over a long period is generally easy to do.
10
10
This means you can have several branches that are always open and that you use for different stages of your development cycle; you can merge regularly from some of them into others.
11
11
12
-
Many Git developers have a workflow that embraces this approach, such as having only code that is entirely stable in their `master` branch – possibly only code that has been or will be released.
13
-
They have another parallel branch named `develop` or `next` that they work from or use to test stability – it isn't necessarily always stable, but whenever it gets to a stable state, it can be merged into `master`.
12
+
Many Git developers have a workflow that embraces this approach, such as having only code that is entirely stable in their `master` branch -- possibly only code that has been or will be released.
13
+
They have another parallel branch named `develop` or `next` that they work from or use to test stability -- it isn't necessarily always stable, but whenever it gets to a stable state, it can be merged into `master`.
14
14
It's used to pull in topic branches (short-lived branches, like your earlier `iss53` branch) when they're ready, to make sure they pass all the tests and don't introduce bugs.
15
15
16
16
In reality, we're talking about pointers moving up the line of commits you're making.
@@ -41,7 +41,7 @@ But in Git it's common to create, work on, merge, and delete branches several ti
41
41
42
42
You saw this in the last section with the `iss53` and `hotfix` branches you created.
43
43
You did a few commits on them and deleted them directly after merging them into your main branch.
44
-
This technique allows you to context-switch quickly and completely – because your work is separated into silos where all the changes in that branch have to do with that topic, it's easier to see what has happened during code review and such.
44
+
This technique allows you to context-switch quickly and completely -- because your work is separated into silos where all the changes in that branch have to do with that topic, it's easier to see what has happened during code review and such.
45
45
You can keep the changes there for minutes, days, or months, and merge them in when they're ready, regardless of the order in which they were created or worked on.
46
46
47
47
Consider an example of doing some work (on `master`), branching off for an issue (`iss91`), working on it for a bit, branching off the second branch to try another way of handling the same thing (`iss91v2`), going back to your `master` branch and working there for a while, and then branching off there to do some work that you're not sure is a good idea (`dumbidea` branch).
@@ -60,4 +60,4 @@ image::images/topic-branches-2.png[History after merging `dumbidea` and `iss91v2
60
60
We will go into more detail about the various possible workflows for your Git project in <<_distributed_git>>, so before you decide which branching scheme your next project will use, be sure to read that chapter.
61
61
62
62
It's important to remember when you're doing all this that these branches are completely local.
63
-
When you're branching and merging, everything is being done only in your Git repository – no server communication is happening.
63
+
When you're branching and merging, everything is being done only in your Git repository -- no server communication is happening.
0 commit comments