Let's say you are working on your feature branch which keeps track of the remote master branch. If your team member adds a new commit to the remote master branch and you want to add that commit to your feature branch then you need to follow the following steps in order to have your feature branch up to date.
Step 1: Check if there is a new commit to the master.
git fetch
or
git fetch -p
The fetch command will give you information about the changes(like new branch has added and many more) in the remotes repository. -p
will give you the same thing except it will give the information about the remote branches that have been deleted by the team member for any good reason. Always remember that fetch will not do any changes in the local repository. It only displays the information about the changes made in the remote repository.
Step 2: Check your feature branch status (not necessarily)
git status
It will show you how many commits you are behind/after the master.
Step 3: If your feature branch is behind one or more commits then Rebase the remote master branch into your feature branch
git rebase origin/master
You can also do it like this
git rebase
As you are keeping track of remote master branch so it will directly rebase the origin/master. But I'll recommend you to use the first approach by explicity saying that I need to rebase the origin/master to my current local repository.
In my opinion, this is the best way to make your feature branch up to date.
Never do merge origin/master to your feature branch git merge
in your local repository
because it will add an extra merge commit in your local repository then your feature branch will have two commits in local one is your feature branch commit and another one is merge commit. So, when you push that same branch to the remote, it will add two commits rather than one commit. Generally, this will not give a clean history of the commits.