How to merge a remote branch into my current branch, but be able to see the file changes as staged changes in git. This happens sometimes, and I can edit in VSCode, but other times it automatically merges everything in.
When working in a branch I want to merge a remote branch into, I run:
git pull origin branch-name
depending on how different my working branch and this remote branch are, sometimes it stages, other times it just merges directly in.
How can I reliably get the staging to happen? thanks
You can ask git merge
(which is implied in your git pull
command) to wait for your approval (after potential edits) with the --no-commit
option.
Important note from the doc:
Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit. Thus, if you want to ensure your branch is not changed or updated by the merge command, use --no-ff with --no-commit.
So, the full process would be
git pull --no-commit --no-ff origin branch-name
# check whatever you need at this point, edit files, run things
# (don't forget to add paths you modified)
# and when you're ready :
git merge --continue
...which will prompt the commit message in your editor with the automatic merge info prepared (which you can edit too).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.