In our previous blog, we set up the GitHub repository and pushed it back into Github. We can see it briefly in the following images.
Git status shows we are in the main branch and it's up to date.
when we pushed the main branch, it also showed everything is timely.
The Git branch shows we are currently in the main branch
Let's create a new branch and switch to the new branch called "branch1"
We can see the branches list and see we are currently in the main ( * shows where we are currently). We used switch and checkout and commands to move from branch to branch. In the final command, we switched to a new branch "branch1"
Let's add some content in the new branch and push it to GitHub.
Here, in the new branch, we created a text file hello.txt and added the content "Hello World".git add hello.txt
command stages the changes that we made to the hello.txt
file. Staging prepares the changes for the next commit.git commit -m "hello world content added"the
command creates a commit to save the staged changes to the Git history. The -m
flag allows you to provide a commit message that describes the changes. Here, the commit message is "Hello world content added."
Finally, we pushed the update in the Github successfully which we can view the updates in the GitHub.
Merging branches
We can now merge the branches to the main branch. Merging branches is a common operation in Git that combines the changes from one branch into another.
We merged "branch1" into the main branch. To merge the branch to the main, first, we need to switch back to the main and perform the merging action.
Happy Learning!!!