Currently if you are in branch V2 and you do "git pull origin V3" it merges V3 to V2 and doesn't even warn or prompt about it. Can this option somehow be blocked? I read all the similar questions here and people suggest I can use fetch or show a warning in this case. This is OK, I will start using fetch instead of pull but I want to block other pull users. Also, I assume there are cases when you have to make pull instead of fetch. Thanks
If you link the remote branch as the local branch upstream source, you won't need to manually write the remote and branch.
# set upstream
git push -u origin V2
# Then simply pull from default branch
git pull
This'll work. Though, you're mostly always better to fetch
and rebase
your local branch on top of the remote. This make a cleaner and more usable history.
To answer the question directly though, you could create a custom before merge hook which check the branches being merged and alert when you're merging a remote branch not matching the local branch name. But, this is overhead and might be annoying as it'll check on every merge (because git pull
=== git fetch && get merge
)
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