GitHub-Branches
Table of contents
- Introduction
- About Default Branch of GitHub
- Why Branches are used in Github
- I am creating a repo to show stuff.
- Git Commands to commit & Add branch
- Commands That You have to use to push on a specific branch on GitHub
- Another way to push in branch if the repo remote origin is already defined
- Types of branches
Introduction
As a beginner in software development, understanding how to use GitHub branches can be quite confusing. However, branches are a fundamental concept that every developer needs to understand to effectively collaborate on projects. In this technical blog, I'll be covering everything you need to know about GitHub branches, including what they are, why they're important, and how to create and manage them. By the end of this blog, you'll have a solid understanding of GitHub branches and be able to use them confidently in your projects. Whether you're a beginner or an experienced developer, this blog will provide valuable insights that will help you work more efficiently with GitHub.
About Default Branch of GitHub
The main branch is the default branch on GitHub, and it is the branch that is created by default when a new project is initialized. When you create a new repository, there is only a single main branch that exists. This branch represents the main line of development for your project, and it is where you'll find the latest stable version of your code. When you make changes to your project, you can create a new branch from the main branch to work on your changes without affecting the stable version of your code. Once you're done with your changes, you can merge them back into the main branch to update the stable version of your code. Understanding how to work with the main branch is a fundamental skill for anyone working with GitHub, and it's essential for collaborating with others on projects.
Why Branches are used in Github
Branches in Git and GitHub are incredibly useful for managing and organizing software projects. They are created to deal with new features, bug fixes, and other changes without merging them into the main project codebase. This allows developers to experiment and make changes without affecting the main project codebase. Another use case for branches is when a team of developers is working on a project. Each developer can work on their branch and test their changes independently. Once the changes are tested and approved, they can be merged back into the main branch. This allows for efficient collaboration and reduces the risk of conflicts and errors. Overall, branches are a powerful tool for managing software development and can greatly improve productivity and efficiency.
I am creating a repo to show stuff.
Git Commands to commit & Add branch
Commands That You have to use to push on a specific branch on GitHub
$git init
$git add .
$git commit -m "write a commit"
$git remote add origin "Add URL of repo inside that specific branch"
$git push origin nameofbranch
Another way to push in branch if the repo remote origin is already defined
$git add .
$git commit -m"write message"
$git push origin branch1:branch2
Now the data will be pushed to branch 2
Types of branches
Your Branches- ones that are created by you
Active Branches -anyone committed within (the last 3 months)
Stale Branches -inactive within (the last 3 months).