Welcome to the world of Git! Today, we're going to dive into a crucial aspect of version control: tracking branches. š±
Branches are like separate lines of development within a Git repository. They allow you to work on different features, fixes, or experiments without affecting the main codebase.
š” Pro Tip: Imagine a tree with multiple branches. Each branch represents a separate line of development, while the trunk (or master branch) is the main line.
To create a new branch, use the following command:
git branch <branch-name>After creating, you can switch to the new branch using:
git checkout <branch-name>Example:
git branch feature-branch
git checkout feature-branchNow that you're on your new branch, you can start making changes to the code.
# Make some changes in your files
# Stage and commit your changes
git add .
git commit -m "Commit message"Once you're satisfied with your changes, you can merge the branch back into the main branch (usually master).
git checkout master
git merge <branch-name>Example:
git checkout master
git merge feature-branchIf there are conflicts during the merge, Git will let you know. You'll need to resolve these conflicts manually before you can complete the merge.
Once you've merged a branch, you can delete it using:
git branch -d <branch-name>Note: You can't delete a branch if it has been merged into another branch. In that case, you'll need to force the deletion using -D instead of -d.
What does Git use to isolate different lines of development?
By now, you should have a solid understanding of how branches work in Git. Branches are a powerful tool for managing your codebase, allowing you to work on multiple features simultaneously without worrying about conflicts.
Happy coding! š»š