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.
- Checkout to develop, make sure to pull the latest code
- Checkout current feature
- 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 ~
touch update_current_branch.sh
chmod +x update_current_branch.sh
Update the file using your favorite code editor
#!/bin/bash
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='~/update_current_branch.sh'
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.
update
1 comment