In this post we're going to learn how a team collaborates on a project and how to use several different git operations.
Git branching
Git makes it possible to create branches so we can test out different project variations.
What is a branch ?
A newly created branch is a different version of the project you're working on.
This branch not only includes commits from the main branch but also includes commits that the main branch does not currently have.
git branch
We use this command to check the current branch.
git branch
The output of this command would be all the branches that the project has. The branch you're currently on will display an asterisk next to it like this.
main
branch-1
branch-2
* feature -1
How to create a new branch ?
By using :
git branch "name-of-the-branch"
Branch names cannot contain space, and should have a descriptive name.
git checkout
You can switch from a branch to another by using the git command
git checkout branch-name
Git merge
To update the main branch and have it include all the modifications made to the new branch we use this command:
git merge name-of-the-branch
First you switch to the main branch then run the command above.
Merge conflicts
If you're collaborating with a team, you will find that the main branch will include new changes than are not present on your branch, especially if these changes is affecting the current files you're working on. This will create merge conflicts.
Merge conflicts is when git is not sure which changes you want to keep.
So when you try to merge git will ask you which version to keep. Delete the version you do not want along with
<<<<<<< HEAD
along with any other git markings such as =====
Delete a branch
To delete a branch we use this command:
git branch -d "your-branch-name"
Top comments (0)