How to Update a Feature Branch from the Latest Develop

Often, we found that our feature branch got behind from the develop branch. Especially when we try to merge to develop long after we create the feature branch. The result of this thing is none other than the big merge conflict.

To avoid this kind of stuff from happening, we need to merge from develop frequently. We have to do it every time so it tend to be boring. This is the step to update from develop.

  1. Checkout to develop, make sure to pull the latest code
  2. Checkout current feature
  3. Git merge develop

This things can be automated so we don’t need to do it manually everytime.

Create a file at your home directory.

cd ~
chmod +x

Update the file using your favorite code editor


echo "Get current branch"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) || exit 1
echo "Current branch: $CURRENT_BRANCH"

echo "Checkout to develop"
git checkout develop || exit 1

echo "Pull develop"
git pull || exit 1

echo "Checkout to $CURRENT_BRANCH"
git checkout $CURRENT_BRANCH || exit 1

echo "Merge from develop"
git merge develop || exit 1

Note: There are a lot of ways to achieve this. This is one of them.

Create an alias for the bash code that we created. Update your .bashrc file using your favorite editor and add this code at the end of the file

alias update='~/' 

Now, you can just update your feature branch by only using a single command update

Go to your repository and checkout your current feature branch. Run the command.


1 comment

Leave a comment

Your email address will not be published. Required fields are marked *