WEBVTT

00:06.410 --> 00:11.420
Let's imagine that I've added some important content to my file.

00:11.420 --> 00:21.250
One staged it with Git at this command and performed a new commit with git commit the same command.

00:21.260 --> 00:28.160
But on this point I want to experiment with this file and perform some tests.

00:28.160 --> 00:33.650
But on the other hand, I don't want to fail anything because it's in production.

00:33.650 --> 00:35.480
That's where exactly we need.

00:35.480 --> 00:36.440
Branching.

00:36.440 --> 00:42.860
Creating a new branch in a project basically means creating a new copy of that project.

00:42.860 --> 00:46.910
You can experiment with this copy without affecting the original.

00:46.910 --> 00:55.190
So if the experiment fails, you can just abandon it and return to the original the master branch.

00:55.190 --> 01:03.920
But if your tests are successful, Git makes it easy to import these experimental elements into the

01:03.920 --> 01:12.530
master and even if you change your mind later on, you can easily revert back to the state of the project

01:12.530 --> 01:14.150
before this merger.

01:14.150 --> 01:21.530
After creating a new branch and git, you can create new commits in a branch while not affecting other

01:21.530 --> 01:22.400
branches.

01:22.400 --> 01:25.430
It is one of the best features of git.

01:25.430 --> 01:33.740
So by default you are in the master branch and it is commonly used that people usually expect to find

01:33.740 --> 01:39.710
the latest up to date code in a particular project in the master branch.

01:39.710 --> 01:46.100
So with that in mind, let's start working with branches and good to see the list of branches and the

01:46.100 --> 01:48.680
current branch you are working on.

01:48.680 --> 01:51.800
Run the following command git branch.

01:51.800 --> 02:00.150
If you have cloned your repository or set a remote, you can see the remote branches to just add dash

02:00.200 --> 02:04.370
a to the command and it will look like git branch dash.

02:04.520 --> 02:10.100
The branches that colored in red signify that they are on a remote.

02:10.100 --> 02:17.350
In my case, I've got just one remote branch and one local branch which is master.

02:17.360 --> 02:21.110
See that asterisk to the left of master?

02:21.110 --> 02:25.790
It indicates that I'm working just now on this branch.

02:25.790 --> 02:31.790
Now let's create a branch and get to create a new branch and stay in your current branch.

02:31.790 --> 02:39.440
Just run the following git branch intel, name it test so I'll type git branch test and press.

02:39.440 --> 02:43.790
Enter however on run and git branch command again.

02:43.790 --> 02:47.510
It seems that the active branch is still the master branch.

02:47.510 --> 02:49.940
To change the active branch.

02:49.940 --> 02:57.160
We can run the check out command so I'll tap check out git check out test.

02:57.170 --> 03:05.540
You can also combine the two commands above and thereby create and check out to a new branch in a single

03:05.540 --> 03:15.040
command by adding dash B to the check out command so you could type git check out dash b test to.

03:15.050 --> 03:23.150
Now if you run git branch command again, you'll see that your active branch is test to the branches

03:23.150 --> 03:30.080
we've just created are based on the latest commit of the current active branch, which in our case is

03:30.080 --> 03:31.010
master.

03:31.010 --> 03:39.680
If you want to create a branch based on a certain commit, let's say we want to use a commit a 9590

03:39.710 --> 03:45.860
you can run the following command git check out dash B test old.

03:45.860 --> 03:50.750
That will be a name for this branch followed by hash.

03:50.750 --> 03:55.070
In my case it will be a 9590.

03:55.100 --> 04:00.260
You can rename a branch by running git branch dash.

04:00.260 --> 04:00.820
Hm.

04:00.860 --> 04:02.660
Temp renamed.

04:02.660 --> 04:09.050
It will rename the current branch to temp renamed name to delete a branch.

04:09.050 --> 04:18.380
Run the following command git branch dash capital dx test two but try not to delete branches unless

04:18.380 --> 04:26.960
you have two as there is not really any downside to keeping branches and you have to delete them only

04:26.960 --> 04:32.780
if the number of branches in the repository becomes too large to be manageable.

04:32.780 --> 04:41.240
Please note that that dash capital D option used in above example deletes a branch even if it is not

04:41.240 --> 04:44.090
synchronized with a remote branch.

04:44.090 --> 04:51.080
This means that if you have commits in your current branch that have not been pushed yet, this capital

04:51.080 --> 04:56.660
D will still delete your branch without providing any warning.

04:56.690 --> 05:02.960
To ensure you don't lose data you can use Dash rd option.

05:02.960 --> 05:05.840
This RD option only deletes a branch.

05:05.980 --> 05:09.310
If it has been synchronized with a remote branch.

05:09.310 --> 05:11.780
So let's try running this now.

05:11.800 --> 05:16.640
I'll tap, give it branch D test one and get.

05:17.020 --> 05:25.480
Should give you a warning and abort the operation as the data hasn't been merged with a branch yet.
