Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Post History

71%
+3 −0
Q&A After git fetch, how to fast forward my branch?

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 requir...

posted 4mo ago by Michael‭  ·  edited 4mo ago by Michael‭

Answer
#2: Post edited by user avatar Michael‭ · 2024-07-31T20:39:02Z (4 months ago)
Link more configuration. Add some more explainer in a footnote.
  • The [answer by hkotsubo](https://software.codidact.com/posts/292136/292140#answer-292140) is correct. But just in case you're being *very specific* about fast-forwarding, it's worth stressing that you can [use `--ff-only`][ff-only] as an option on the merge to abort if it requires a merge commit.
  • ```sh
  • 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.
  • ```ini
  • [pull]
  • ff = only
  • ```
  • But that only happens for pulls. If I explicitly ask for a merge after fetching, Git's going to give me a merge, even if it makes a merge commit&hellip; unless I `--ff-only` it not to.
  • [ff-only]: https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---ff-only
  • The [answer by hkotsubo](https://software.codidact.com/posts/292136/292140#answer-292140) is correct. But just in case you're being *very specific* about fast-forwarding, it's worth stressing that you can [use `--ff-only`][ff-only] as an option on the merge to abort if it requires a merge commit.
  • ```sh
  • git merge --ff-only origin/branch_name
  • ```
  • Where is this useful? I have [my `git pull` set to fail][ff-pull] if the merge would create a merge commit. Typically, I'd rather rebase my new commits than make a merge commit unnecessarily.
  • ```ini
  • [pull]
  • ff = only
  • ```
  • But that only happens for pulls.[^ff-merge] If I explicitly ask for a merge after fetching, Git's going to give me a merge, even if it makes a merge commit&hellip; unless I `--ff-only` it not to.
  • [ff-only]: https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---ff-only
  • [ff-merge]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-mergeff
  • [ff-pull]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-pullff
  • [^ff-merge]: This configuration can be [added for merges][ff-merge] as well [as for pulls][ff-pull], but I find that the `pull.ff` config set to `only` 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 setting `merge.ff` to `only`, since I only ever `git merge` commits I already have locally and I'm pretty cognizant of when it'll merge or fast forward.
#1: Initial revision by user avatar Michael‭ · 2024-07-31T15:45:43Z (4 months ago)
The [answer by hkotsubo](https://software.codidact.com/posts/292136/292140#answer-292140) is correct. But just in case you're being *very specific* about fast-forwarding, it's worth stressing that you can [use `--ff-only`][ff-only] as an option on the merge to abort if it requires a merge commit.

```sh
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.

```ini
[pull]
    ff = only
```

But that only happens for pulls. If I explicitly ask for a merge after fetching, Git's going to give me a merge, even if it makes a merge commit&hellip; unless I `--ff-only` it not to.

[ff-only]: https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---ff-only