How do I safely git merge branch to master while keeping my feature branch updated with changes from master?

When working on a branch like test alongside other developers committing to master, how can I keep test updated with the latest master commits? Which is the correct approach to git merge branch to master: merging test into master directly, or pulling and pushing changes between branches? Also, how does avoiding --rebase affect this process?

I’ve been working with Git for a while now, and in my early days, I learned that the safest way to git merge branch to master is by first making sure your feature branch is up to date. It saves a ton of headache later. Here’s what I typically do:

git checkout test  
git merge master  

This pulls in all the latest changes from master into my feature branch (test), which helps me catch conflicts early. Once I’m confident everything works as expected, I finish off with:

git checkout master  
git merge test  

Also, I usually avoid --rebase during this workflow to keep the commit history clear and team-friendly

Totally agree, @miro.vasil. I’ve been following a similar approach, but over time I started fetching from origin/master instead of just master to ensure I’m working with the absolute latest from remote. This way, when I git merge branch to master, there are fewer surprises. So my go-to steps are:

git checkout test  
git fetch origin  
git merge origin/master  

It keeps my local feature branch aligned with remote master. Later, merging test into master becomes smooth. I also skip --rebase unless I’m cleaning up before a final merge because rebasing after pushing can complicate things when you’re collaborating.

Great points, both of you. I’ve been managing Git workflows for about 6 years now, and from what I’ve seen in teams, regularly syncing your feature branch is a game-changer. Especially before you git merge branch to master, running:

git checkout test  
git pull origin master  

helps spot any issues before they become blockers. It’s especially helpful during active development when master is constantly evolving. And yes, I’m also in the no-rebase-on-shared-branches camp—too risky if someone else is working off your feature branch. Keeping things merge-based makes the process more predictable for everyone