feature1 Branch
commit1 commit2
Master Branch /--------------|------------|----
-----|---------------|----------/
commit1 commit2 \---------------|------------|----
commit1 commit2
feature2 Branch
Source: G:\xampp8\TUTORIALS\GIT\BRANCHES
You can have as many branches in your repository if you want,
(examlple: MASTER) = ACTIVE or CURRENT Checked out = Is the currently active or the checked out branch
Local and Remote Branches: 99% are local.
Start in a repositori, otherwise, create a new one: git init; git add .; git commit -m "commit1"
Add a commit:$ git commit -m "commit2"
Usually is the production version of your code
Master Branch
-----O---------------O----------
| |
commit1 commit2
$ git branch feature1
Create and checkout branch with one command:
$ git checkout -b feature1
Show all branches:$ git branch -a
* master
feature1
* means the checked out branch
$ git checkout feature1
Add 2 commits to feature1:
$ git commit -m "commit1"
$ git commit -m "commit2"
$ git branch -a
feature1
Master Branch /--------------|------------|----
-----|---------------|----------/ commit1 commit2
commit1 commit2
To delete feature1
$ git branch -d feature1
$ git branch -a
Master Branch
-----|---------------|----------
commit1 commit2
Multiple Branches
You can have multiple branches, if for example, you have to developers working on two different features.
$ git checkout -b feature2
$ git commit -m "commit1"
$ git commit -m "commit2"
$ git branch -a
feature1 Branch
f1-commit1 f1-commit2
Master Branch /--------------|------------|----
-----|---------------|----------/
commit1 commit2 \---------------|------------|----
f2-commit1 f2-commit2
feature2 Branch
To merge a branch into master:
$ git checkout master
$ git merge feature1
For an example, checkout this video: