Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating and Managing Branches in Git
Branching in Git allows you to work on different versions of your project independently. Here’s how to create, switch, merge, and rebase branches using essential Git commands.
1. Create a Branch
To create a new branch:
Example:
2. Switch Between Branches
You can switch branches using:
Or, in newer versions of Git:
Example:
git checkout feature/login # or git switch feature/login3. Create and Switch to a Branch
Create a new branch and switch to it immediately:
Example:
git checkout -b feature/signup # or git switch -c feature/signup4. List Branches
To see all branches in your repository:
5. Merge Branches
To merge changes from one branch (e.g.,
feature/login) into your current branch (e.g.,main):6. Rebase Branches
Rebasing applies your changes on top of another branch’s history:
This moves the
feature/loginbranch to begin on the tip ofmain, replaying your commits.7. Delete a Branch
After merging, you may want to delete a branch:
Example:
Summary Table
git branch feature/logingit checkout feature/logingit checkout -b feature/signupgit branchgit merge feature/logingit rebase maingit branch -d feature/loginReference
For more details, see the Git Branching documentation.