How to "git pull" from master into the development branch
Categories:
How to Safely 'git pull' from Master into a Development Branch

Learn the best practices for integrating changes from your master (or main) branch into a feature or development branch using git pull
, ensuring a smooth workflow and minimizing conflicts.
In Git-based development workflows, it's common to work on new features or bug fixes in dedicated development branches. Periodically, you'll need to update your development branch with the latest changes from the master
(or main
) branch to avoid significant divergence and simplify future merges. This article will guide you through the process of effectively pulling changes from master
into your current development branch.
Understanding 'git pull' and its Components
git pull
is a convenience command that essentially performs two operations: git fetch
followed by git merge
. When you git pull origin master
into your current branch, Git first fetches the latest changes from the remote master
branch and then attempts to merge those changes into your local branch. Understanding this two-step process is crucial for conflict resolution and maintaining a clean history.
flowchart TD A[Start on dev-branch] --> B{git fetch origin}; B --> C[Local repo updated with remote master]; C --> D{git merge origin/master}; D --> E{Conflicts?}; E -- Yes --> F[Resolve conflicts]; E -- No --> G[Merge successful]; F --> G; G --> H[dev-branch updated];
Workflow of git pull
from master into a development branch.
Preparing Your Development Branch
Before pulling changes from master
, it's good practice to ensure your current development branch is in a clean state. This means committing or stashing any uncommitted changes to prevent them from interfering with the merge process. A clean working directory makes conflict resolution much simpler if it arises.
git status
to check your working directory.1. Step 1: Switch to your development branch
Ensure you are on the correct development branch where you want to integrate the master
changes.
2. Step 2: Commit or stash your current work
Make sure your working directory is clean. If you have uncommitted changes, either commit them or temporarily stash them.
3. Step 3: Pull changes from master
Fetch and merge the latest changes from the remote master
branch into your current development branch.
4. Step 4: Resolve any merge conflicts
If conflicts occur, Git will notify you. Open the conflicting files, resolve the differences, and then mark them as resolved.
5. Step 5: Complete the merge
After resolving conflicts, commit the merge to finalize the integration of master
's changes into your development branch.
# 1. Switch to your development branch
git checkout development-branch
# 2. (Optional) Stash uncommitted changes if any
git stash save "WIP before pulling master"
# 3. Pull changes from master into your current branch
git pull origin master
# 4. If conflicts occur, resolve them
# (Edit files, then add them)
git add .
# 5. Commit the merge (Git will often pre-fill the message)
git commit -m "Merge remote-tracking branch 'origin/master' into development-branch"
# 6. (Optional) Apply stashed changes back
git stash pop
Commands for pulling master
into a development branch.
git pull
command defaults to git pull origin <current-branch>
if no remote and branch are specified. However, explicitly stating origin master
ensures you're pulling from the correct source.Alternative: Rebase Instead of Merge
While git pull
performs a merge by default, you can configure it to rebase instead, or explicitly use git pull --rebase
. Rebasing rewrites your branch's history to appear as if your changes were made after the master
changes, resulting in a linear history. This can be cleaner but requires more caution, especially if your branch has already been pushed and shared with others.
# To pull with rebase
git checkout development-branch
git pull --rebase origin master
Using git pull --rebase
for a linear history.