From 00d0435f649e93fa468c7fa485c5c3e6ed24526f Mon Sep 17 00:00:00 2001 From: Jiri Hubacek Date: Thu, 28 Jun 2018 08:44:54 +0200 Subject: [PATCH] Add branching docs - Add outline. - Add branching, explore, split, merge, rebase info. - Add cheat sheet. --- branching.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 branching.md diff --git a/branching.md b/branching.md new file mode 100644 index 0000000..d245359 --- /dev/null +++ b/branching.md @@ -0,0 +1,43 @@ +# Branching +It's not a good idea to multitask when working. However, some projects just +need it. The reason can be multiple features you are developing in parallel or +more than one guy working on the project. To keep track of different changes +that are realated the concept of branches was introduced. + +Branch is just alternative history that can be merged one day back to the main +history. The main history branch is named `master` by default. + +# Explore - show branches +`git branch` command show all the local branches and the active branch you are +currently on. + +# Split - create alternative branch +When decided to create new branch `git checkout -b NAME` can be used. Switching +between branches is done by `git checkout NAME` command. + +# Merge - join multiple branches +To the current branch, any other branch may be merged. The result is history +that contains all commits in both branches. Command `git merge --no-ff NAME` +will merge the branch `NAME` to itself. `--no-ff` avoids melting the branch +being merged. It's hard to explain, better to show. + +# Rebase - change the base commit of branch +Each branch start at some commit. This starting commit of the branch can be +also changed usually because of keeping clean history. The command `git rebase +COMMIT` takes current branch and put it on top of the `COMMIT`. + +# Cheat sheet +## Explore +- `git branch` + +## Split +- `git checkout -b NAME` +- `git checkout -b NAME COMMIT` +- `git checkout NAME` + +## Merge +- `git merge --no-ff NAME` + +## Rebase +- `git rebase COMMIT` +- `git rebase -i COMMIT` -- 2.39.2