I constantly need to update my remote branch with current master. I am trying to automate this as;
#!/usr/bin/env bash
cd directory
git checkout master
git pull
git checkout <remote_branch>
git pull origin <remote_branch>
git merge master
git push
but when I merge master I am thrown into my editor where I need to :wq to be able to push. How can I replicate this :wq in my Bash script?
There are 3 ways listed below to do this and you don’t have to replicate :wqto do so.
--no-editusing the --no-edit option, the auto-generated message will be accepted (this is generally discouraged, see the git docs)
So after you git pull origin <remote_branch>, you can use
git merge master --no-edit
Older scripts may depend on the historical behaviour of not allowing the user to edit the merge log message. They will see an editor opened when they run git merge. To make it easier to adjust such scripts to the updated behaviour, the environment variable
GIT_MERGE_AUTOEDITcan be set tonoat the beginning of them. — git docs
Use
GIT_MERGE_AUTOEDIT=no
before the merge line
-m to provide the messageSet the commit message to be used for the merge commit (in case one is created).
If --log is specified, a shortlog of the commits being merged will be appended to the specified message.
The
git fmt-merge-msgcommand can be used to give a good default for automated git merge invocations. The automated message can include the branch description. — git docs
git merge master -m "Merge master"
Read more: the git merge command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With