Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on After git fetch, how to fast forward my branch?
Parent
After git fetch, how to fast forward my branch?
I did git fetch
to quickly get latest commits. I did this instead of git pull
so I could deal with merge conflicts offline. But my repository is still stuck on the old commit, and now git pull
fails because I can no longer connect to the internet. How do I "activate" the changes that I fetched?
Post
The answer by hkotsubo is correct. But just in case you're being very specific about fast-forwarding, it's worth stressing that you can use --ff-only
as an option on the merge to abort if it requires a merge commit.
git merge --ff-only origin/branch_name
Where is this useful? I have my git pull
set to fail if the merge would create a merge commit. Typically, I'd rather rebase my new commits than make a merge commit unnecessarily.
[pull]
ff = only
But that only happens for pulls.[1] If I explicitly ask for a merge after fetching, Git's going to give me a merge, even if it makes a merge commit… unless I --ff-only
it not to.
-
This configuration can be added for merges as well as for pulls, but I find that the
pull.ff
config set toonly
gives me the confidence to pull whenever I want. If a fast forward is unavailable, Git just does a fetch without merging. I don't bother settingmerge.ff
toonly
, since I only evergit merge
commits I already have locally and I'm pretty cognizant of when it'll merge or fast forward. ↩︎
0 comment threads