We talked about branches quite a bit already.
Now let's investigate what exactly they are.
So branches are used to develop new features in isolation
from the main branch.
It's like your testing environment.
And the main branch is the default branch.
Other branches can be manually added.
Notice that the name main depends on your discretion.
I call it main in my demo.
Maybe you didn't change anything.
It's called master or whatever you want.
Any Git repository can have multiple branches
to allow developer to work independently.
And after completion, once the changes have been approved,
you merge the branches back to the main.
So if these branches have different states,
it's important to be able to compare your branches.
And you can do that using the git diff command.
So git diff followed by the name of the two branches
will preview branch differences
and see if there are any potential conflicts.
To merge another branch in your active branch,
use git merge followed by the branch name
that you want to merge into there.
And use git checkout minus B followed by some name
to create a new branch and start using it.
Once done, git push origin dev branch
to push the new branch to the remote repository.
That makes sense because you want the branch
to be visible for other developers as well
before the changes are going to be merged in the main branch.
Then you use git checkout main to switch back to the main.
And to clean up your work,
once the changes have been integrated in the main,
you can delete the branch using git branch minus D dev branch.
Let me demonstrate.
So I'm starting by using a branch,
git branch new files.
And then I'm using git status.
And git status is saying that the current branch is main.
Now I want to change that,
so I'm using git checkout new files.
And then I'm creating a new file,
echo 3 greater than 3.txt.
Who cares about the name?
Git add star followed by git commit minus M
3 in new branch.
Better be specific.
Then I'm going to use git push minus minus set upstream
origin new files.
And next I'm using git status.
And there I can see on branch new files.
I'm using LS.
And we can see 3.txt.
And next I'm going to use git checkout main.
And I'm using LS again.
And 3.txt is gone.
Git status is confirming that I'm in the main branch.
And I don't have my 3.txt file.
Oh, no.
What is going on?
Well, that is what's happening if you are working in branch.
I went to the branch new files.
I created a file in that branch.
And nothing has happened with it.
So what are we going to do with it?
That's what you will learn in the next video.