1
00:00:00,000 --> 00:00:09,000
We talked about branches quite a bit already.

2
00:00:09,000 --> 00:00:12,000
Now let's investigate what exactly they are.

3
00:00:12,000 --> 00:00:15,000
So branches are used to develop new features in isolation

4
00:00:15,000 --> 00:00:16,000
from the main branch.

5
00:00:16,000 --> 00:00:18,000
It's like your testing environment.

6
00:00:18,000 --> 00:00:21,000
And the main branch is the default branch.

7
00:00:21,000 --> 00:00:24,000
Other branches can be manually added.

8
00:00:24,000 --> 00:00:27,000
Notice that the name main depends on your discretion.

9
00:00:27,000 --> 00:00:29,000
I call it main in my demo.

10
00:00:29,000 --> 00:00:30,000
Maybe you didn't change anything.

11
00:00:30,000 --> 00:00:34,000
It's called master or whatever you want.

12
00:00:34,000 --> 00:00:36,000
Any Git repository can have multiple branches

13
00:00:36,000 --> 00:00:39,000
to allow developer to work independently.

14
00:00:39,000 --> 00:00:43,000
And after completion, once the changes have been approved,

15
00:00:43,000 --> 00:00:46,000
you merge the branches back to the main.

16
00:00:46,000 --> 00:00:49,000
So if these branches have different states,

17
00:00:49,000 --> 00:00:52,000
it's important to be able to compare your branches.

18
00:00:52,000 --> 00:00:54,000
And you can do that using the git diff command.

19
00:00:54,000 --> 00:00:57,000
So git diff followed by the name of the two branches

20
00:00:57,000 --> 00:00:59,000
will preview branch differences

21
00:00:59,000 --> 00:01:02,000
and see if there are any potential conflicts.

22
00:01:02,000 --> 00:01:05,000
To merge another branch in your active branch,

23
00:01:05,000 --> 00:01:07,000
use git merge followed by the branch name

24
00:01:07,000 --> 00:01:10,000
that you want to merge into there.

25
00:01:10,000 --> 00:01:13,000
And use git checkout minus B followed by some name

26
00:01:13,000 --> 00:01:17,000
to create a new branch and start using it.

27
00:01:17,000 --> 00:01:20,000
Once done, git push origin dev branch

28
00:01:20,000 --> 00:01:23,000
to push the new branch to the remote repository.

29
00:01:23,000 --> 00:01:25,000
That makes sense because you want the branch

30
00:01:25,000 --> 00:01:28,000
to be visible for other developers as well

31
00:01:28,000 --> 00:01:32,000
before the changes are going to be merged in the main branch.

32
00:01:32,000 --> 00:01:37,000
Then you use git checkout main to switch back to the main.

33
00:01:37,000 --> 00:01:39,000
And to clean up your work,

34
00:01:39,000 --> 00:01:42,000
once the changes have been integrated in the main,

35
00:01:42,000 --> 00:01:46,000
you can delete the branch using git branch minus D dev branch.

36
00:01:46,000 --> 00:01:48,000
Let me demonstrate.

37
00:01:48,000 --> 00:01:50,000
So I'm starting by using a branch,

38
00:01:50,000 --> 00:01:55,000
git branch new files.

39
00:01:55,000 --> 00:01:57,000
And then I'm using git status.

40
00:01:57,000 --> 00:02:02,000
And git status is saying that the current branch is main.

41
00:02:02,000 --> 00:02:04,000
Now I want to change that,

42
00:02:04,000 --> 00:02:09,000
so I'm using git checkout new files.

43
00:02:09,000 --> 00:02:11,000
And then I'm creating a new file,

44
00:02:11,000 --> 00:02:16,000
echo 3 greater than 3.txt.

45
00:02:16,000 --> 00:02:18,000
Who cares about the name?

46
00:02:18,000 --> 00:02:25,000
git add star followed by git commit minus M

47
00:02:25,000 --> 00:02:30,000
3 in new branch.

48
00:02:30,000 --> 00:02:32,000
Better be specific.

49
00:02:32,000 --> 00:02:38,000
Then I'm going to use git push minus minus set upstream

50
00:02:38,000 --> 00:02:41,000
origin new files.

51
00:02:41,000 --> 00:02:45,000
And next I'm using git status.

52
00:02:45,000 --> 00:02:48,000
And there I can see on branch new files.

53
00:02:48,000 --> 00:02:49,000
I'm using LS.

54
00:02:49,000 --> 00:02:52,000
And we can see 3.txt.

55
00:02:52,000 --> 00:02:56,000
And next I'm going to use git checkout main.

56
00:02:56,000 --> 00:02:58,000
And I'm using LS again.

57
00:02:58,000 --> 00:03:01,000
And 3.txt is gone.

58
00:03:01,000 --> 00:03:05,000
Git status is confirming that I'm in the main branch.

59
00:03:05,000 --> 00:03:07,000
And I don't have my 3.txt file.

60
00:03:07,000 --> 00:03:09,000
Oh no, what is going on?

61
00:03:09,000 --> 00:03:12,000
Well, that is what's happening if you are working in branch.

62
00:03:12,000 --> 00:03:14,000
I went to the branch new files.

63
00:03:14,000 --> 00:03:16,000
I created a file in that branch,

64
00:03:16,000 --> 00:03:18,000
and nothing has happened with it.

65
00:03:18,000 --> 00:03:20,000
So what are we going to do with it?

66
00:03:20,000 --> 00:03:22,000
That's what you will learn in the next video.

