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/1-git-branching.asc
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -493,7 +493,6 @@ Conflicts:
493
493
494
494
You can modify that message with details about how you resolved the merge if you think it would be helpful to others looking at this merge in the future – why you did what you did, if it's not obvious.
495
495
496
-
497
496
=== Branch Management
498
497
499
498
Now that you've created, merged, and deleted some branches, let's look at some branch-management tools that will come in handy when you begin using branches all the time.
@@ -509,7 +508,7 @@ $ git branch
509
508
testing
510
509
----
511
510
512
-
Notice the `*` character that prefixes the `master` branch: it indicates the branch that you currently have checked out.
511
+
Notice the `*` character that prefixes the `master` branch: it indicates the branch that you currently have checked out (i.e., the branch that `HEAD` points to).
513
512
This means that if you commit at this point, the `master` branch will be moved forward with your new work.
514
513
To see the last commit on each branch, you can run `git branch -v`:
515
514
@@ -565,7 +564,7 @@ Because Git uses a simple three-way merge, merging from one branch into another
565
564
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.
566
565
567
566
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.
568
-
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`.
567
+
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`.
569
568
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.
570
569
571
570
In reality, we're talking about pointers moving up the line of commits you're making.
@@ -610,13 +609,15 @@ Your history then looks like this:
610
609
.History after merging `dumbidea` and `iss91v2`
611
610
image::images/18333fig0321-tn.png[History after merging `dumbidea` and `iss91v2`.]
612
611
612
+
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.
613
+
613
614
It's important to remember when you're doing all this that these branches are completely local.
614
615
When you're branching and merging, everything is being done only in your Git repository – no server communication is happening.
615
616
616
617
=== Remote Branches
617
618
618
-
Remote branches are references to the state of branches on your remote repositories.
619
-
They're local branches that you can't move; they're moved automatically whenever you do any network communication.
619
+
Remote branches are references (pointers) to the state of branches in your remote repositories.
620
+
They're local branches that you can't move; they're moved automatically for you whenever you do any network communication.
620
621
Remote branches act as bookmarks to remind you where the branches on your remote repositories were the last time you connected to them.
621
622
622
623
They take the form `(remote)/(branch)`.
@@ -625,8 +626,8 @@ If you were working on an issue with a partner and they pushed up an `iss53` bra
625
626
626
627
This may be a bit confusing, so let's look at an example.
627
628
Let's say you have a Git server on your network at `git.ourcompany.com`.
628
-
If you clone from this, Gitautomatically names it `origin` for you, pulls down all its data, creates a pointer to where its `master` branch is, and names it `origin/master` locally; and you can't move it.
629
-
Git also gives you your own `master` branch starting at the same place as origin's `master` branch, so you have something to work from.
629
+
If you clone from this, Git's `clone` command automatically names it `origin` for you, pulls down all its data, creates a pointer to where its `master` branch is, and names it `origin/master` locally.
630
+
Git also gives you your own local `master` branch starting at the same place as origin's `master` branch, so you have something to work from.
630
631
631
632
[NOTE]
632
633
.``origin'' is not special
@@ -637,14 +638,14 @@ Just like the branch name ``master'' does not have any special meaning in Git, n
637
638
.Server and local repositories after cloning
638
639
image::images/18333fig0322-tn.png[Server and local repositories after cloning.]
639
640
640
-
If you do some work on your local master branch, and, in the meantime, someone else pushes to `git.ourcompany.com` and updates its master branch, then your histories move forward differently.
641
+
If you do some work on your local master branch, and, in the meantime, someone else pushes to `git.ourcompany.com` and updates its `master` branch, then your histories move forward differently.
641
642
Also, as long as you stay out of contact with your origin server, your `origin/master` pointer doesn't move.
642
643
643
644
.Local and remote work can diverge
644
645
image::images/18333fig0323-tn.png[Local and remote work can diverge.]
645
646
646
647
To synchronize your work, you run a `git fetch origin` command.
647
-
This command looks up which server origin is (in this case, it's `git.ourcompany.com`), fetches any data from it that you don't yet have, and updates your local database, moving your `origin/master` pointer to its new, more up-to-date position.
648
+
This command looks up which server ``origin'' is (in this case, it's `git.ourcompany.com`), fetches any data from it that you don't yet have, and updates your local database, moving your `origin/master` pointer to its new, more up-to-date position.
648
649
649
650
.`git fetch` updates your remote references
650
651
image::images/18333fig0324-tn.png[`git fetch` updates your remote references.]
@@ -680,7 +681,7 @@ Delta compression using up to 8 threads.
@@ -719,7 +720,7 @@ Switched to a new branch 'serverfix'
719
720
720
721
This gives you a local branch that you can work on that starts where `origin/serverfix` is.
721
722
722
-
==== Tracking/Upstream Branches
723
+
==== Tracking Branches
723
724
724
725
Checking out a local branch from a remote branch automatically creates what is called a ``tracking branch'' (or sometimes an ``upstream branch'').
725
726
Tracking branches are local branches that have a direct relationship to a remote branch.
@@ -748,7 +749,8 @@ Branch sf set up to track remote branch serverfix from origin.
748
749
Switched to a new branch 'sf'
749
750
----
750
751
751
-
Now, your local branch sf will automatically push to and pull from origin/serverfix.
752
+
Now, your local branch sf will automatically push to and pull from `origin/serverfix`.
753
+
752
754
If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you're tracking, you can use the `-u` or `--set-upstream-to` option to `git branch` to explicitly set it at any time.
0 commit comments