As a software developer, you must have come across a situation where you need to merge code from the master branch into the development branch.
This process is called “git pull”.
In this tutorial, we will learn how to perform a git pull from the master branch into the development branch with code examples.
Understanding Git Branches
Before we dive into the git pull process, let’s understand what Git branches are.
In Git, a branch is a separate line of development that allows multiple developers to work on the same project simultaneously.
The main branch in Git is called the “master” branch, and it contains the production-ready code.
The development branch is where developers work on new features and bug fixes, and once the code is ready, it is merged into the master branch.
Git Pull from Master Branch into Development Branch
To perform a git pull from the master branch into the development branch, follow these steps:
Checkout the development branch
Before you start the pull process, make sure that you are on the development branch.
You can use the following command to checkout the development branch:
$ git checkout development
Fetch the latest changes from the master branch
Before you pull the changes, it is always a good practice to fetch the latest changes from the master branch.
You can use the following command to fetch the changes:
$ git fetch origin master
Merge the changes from the master branch into the development branch
Once you have fetched the latest changes from the master branch, you can merge the changes into the development branch.
You can use the following command to merge the changes:
$ git merge origin/master
Resolve any conflicts
If there are any conflicts between the code in the development branch and the code in the master branch, Git will notify you.
You need to resolve these conflicts manually by editing the code.
Once you have resolved the conflicts, you can use the following command to stage the changes:
$ git add .
Commit the changes:
Finally, you need to commit the changes to the development branch.
You can use the following command to commit the changes:
$ git commit -m "Merged changes from master branch into development branch"
Conclusion
In this tutorial, we have learned how to perform a git pull from the master branch into the development branch.
We have also covered the basics of Git branches and the steps involved in the git pull process.
By following these steps, you can easily merge code from the master branch into the development branch and keep your project up to date.