If you're working on your project alone, you don't have to worry about much, you just use just three following commands and push the code to you respective repository.

  1. git add <fileName>

    If you want to push all the changes you used git add .

  2. git commit -m "any commit message"

  3. git push

And git status command to check the status, which file is deleted, modified, etc.

But working on, some group project or some open-source project, where large code bases and too many commits and PR are there, can be quite overwhelming in the start.

In open-source projects, you can use this knowledge to contribute there too, if you are stuck anywhere, various cool people will help you, so don't hesitate to reach out. But ask meaningful questions. Before asking them just Google and try to find a solution, If you are still stuck, go ahead and ask them.

To contribute to the open-source project, we should have a basic understanding of the specific field, to which we want to contribute in the project. You should have basic knowledge of git and GitHub, all other things you'll learn and understand as you proceed.

When I started to contribute, I felt that I should started previously, It's not that tough. So, if you want to contribute to the open-source project, don't hesitate.

In this blog, I'm going to cover some git branch concepts, and explain pictorially, how it's working.

Branching

Git branches are essential for maintaining a clean and organized codebase, enabling parallel development, and facilitating collaboration in software development projects. They help manage code changes, isolate work, and provide a structured way to develop and maintain software.

Here are some of the following git commands related with branching in git:-

  1. To create the branch

     git checkout -b "BranchName"
    
  2. To check if the remote is added successfully or not use this command

     git remote -v
    
  3. To delete the branch

     git branch -d "BranchName"
    
  4. To push our code which will send the local commits to the remote branch of the repository

     git push origin main
    

So, why git branch?

Whether you are starting your project or contributing to others, these git commands will help you to add your code and create your first PR(Pull Request) too.

Here, I made the original branch as main branch.

To create a new branch,

git checkout -b "b1"

Suppose there are many commits added to the main branch branch but you're at the previous version.

To update the branch after the change in the main branch.

git rebase main

Working on the different branches can be painful. To switch between the branches while working on another branch. Use this

git switch <go_to_branch>

Branches should be deleted after merging to the main branch, just by clicking the delete branch this button.

But it'll not be deleted in your local, To do that use

git branch -D <branchName>

To add the changes in the specific branch of the repository, use these

  1. git add <fileName>

    If you want to push all the changes you used git add .

  2. git commit -m "any commit message"

  3. git push origin <branch_name>

Thanks for reading this blog.

Check out my Portfolio website click me.

Please give like, if you like this blog.

Did you find this article valuable?

Support Anurag's blog by becoming a sponsor. Any amount is appreciated!