]> rtime.felk.cvut.cz Git - hubacji1/oneflow.git/blob - branching.md
Update rebase section
[hubacji1/oneflow.git] / branching.md
1 # Branching
2 It's not a good idea to multitask when working. However, some projects just
3 need it. The reason can be multiple features you are developing in parallel or
4 more than one guy working on the project. To keep track of different changes
5 that are realated the concept of branches was introduced.
6
7 Branch is just alternative history that can be merged one day back to the main
8 history. The main history branch is named `master` by default.
9
10 # Explore branches
11 `git branch` command show all the local branches and the active branch you are
12 currently on. Show remote branches by `git branch --all` command.
13
14 # Create and switch branches
15 When decided to create new branch `git branch NAME` can be used. The branch
16 will be created from the current state called *HEAD*. Switching between
17 branches is done by `git checkout NAME` command. Checkout to specific commit is
18 also possible by `git checkout COMMIT_ID`.
19
20 If branch creation from specified commit is prefered, use `git branch NAME
21 COMMIT_ID`.
22
23 # Merge multiple branches
24 To the current branch, any other branch may be merged. The result is history
25 that contains all commits in both branches. Command `git merge --no-ff NAME`
26 will merge the branch `NAME` to itself. `--no-ff` avoids melting the branch
27 being merged. It's hard to explain, better to show.
28
29 # Change the base commit of branch
30 Each branch start at some commit. This starting commit of the branch can be
31 also changed. The usual case is keeping clean history. The command `git rebase
32 COMMIT_ID` takes current branch and put it on top of the `COMMIT_ID`. Also,
33 `git rebase NAME` could be used for rebasing current branch on top of other.
34
35 # Cheat sheet
36 ## Explore
37 - `git branch`
38 - `git branch --all`
39
40 ## Create
41 - `git branch NAME`
42 - `git branch NAME COMMIT_ID`
43 - `git checkout NAME`
44 - `git checkout COMMIT_ID`
45
46 ## Merge
47 - `git merge --no-ff NAME`
48
49 ## Rebase
50 - `git rebase COMMIT_ID`
51 - `git rebase -i COMMIT_ID`
52 - `git rebase NAME`