Git Branching
Git Branching
What is a branch?
After 3 commits
Add a branch
NOTE: This also reverts files in your working directory (e.g., c:\mycode) back
to master.
So edit to test.rb no longer in your working directory (but you havent lost it, as
long as you committed before switching remember it will be in your local
database. But dont delete .git!)
Example
Example, continued
# create a branch
git branch
theTree = "Aspen";
}
@Override
public String toString() {
return "TheBrancher [theLeaf=" +
theLeaf + ",
theTree=" + theTree + "]";
}
# and in main
brancher.makeATree();
System.out.println(brancher);
git
git
status
go back to master
git
#
checkout master
Basic Merging
No conflicts
git checkout -b
NOTE: git wont let you switch to master if you have uncommitted changes that
conflict with the code youre checking out. So you should have a clean slate before
you switch (stash and amend can deal with this later topics)
Basic merge
$ git checkout master
$ git merge iss53
Merge made by recursive.
README | 1 +
1 files changed, 1 insertions(+), 0
deletions(-)
Remote Branches
Supplemental Material
Remote Branches
Branches diverging
Tracking Branch
Forking
Configuration
Continued
If you have made a commit, but haven't shared it with anyone else
and you decide you don't want it, then you can usegit resetto
rewrite the history so that it looks as though you never made that
commit.
These are just some of the possible usage scenarios. There are
other commands that can be useful in some situations, and the
above three commands have other uses as well.