Doug Schmidt
Doug Schmidt

Reputation: 217

Can I configure pulls from an upstream repo to always be fast-forward only?

My team uses a feature-branch workflow with git.

I'd like to somehow config a git pull upstream branchname from the upstream repo to always be git pull --ff-only upstream branchname. Is that possible?

I'd also be happy if I could configure the entire upstream repo to only allow --ff-only pulls.

Details

Our main integration branch is develop in the main upstream repo, with individual feature branches starting from develop, making their changes, and then raising pull requests to merge the feature branches back to develop.

The problem is that many of our developers are not as git-savvy as they should be, and they keep messing up their local repo's copy of develop, so that it diverges from the upstream copy of develop.

They don't notice this this divergence. They then create a feature branch from their borked develop, and don't realize it until they raise their pull request, which suddenly brings in a ton of crap. If we're lucky, a savvy reviewer tells them to clean up their pull request by rebasing. But every now and then a messed up pull request gets merged back and that messes up our upstream history.

Workaround

My recommendation to these novice git-folks is to always use the --ff-only option when pulling from upstream, to force their local develop branch to remain a perfect copy of the upstream repo.

If their local copy of develop has diverged from upstream, then the --ff-only option will yell at them when they next try to pull. This yelling will force them to fix the real problem.

But they are git-n00bs and so they often don't even understand what I'm recommending, and just continue to mess things up.

I'll try all the appropriate carrot/stick motivational techniques (Humans! I know, right?), but if I could just somehow configure their local repos with --ff-only training wheels, then my review burden will go down (and my devs will be forced to learn better git techniques).

Upvotes: 1

Views: 62

Answers (2)

Levi Haskell
Levi Haskell

Reputation: 853

WARNING: UNDOCUMENTED HACK

The git pull command is actually a shell script usually found in the libexec/git-core/git-pull directory under your git installation. This script internally calls git fetch and git merge commands in sequence.

Technically you can open this file and edit it to your liking. For example: initializing ff_only shell variable to '--ff-only' instead of '', will accomplish what want but may conflict with other options like --ff that user may specify explicitly. Off course, you can further modify the script to accommodate this as well.

However beware that installing a new version of git will most likely overwrite your changes. It all depends how determined you are to accomplish what you're trying to do.

Upvotes: 0

Levi Haskell
Levi Haskell

Reputation: 853

You can create a git alias for this, for example:

git config --global alias.update 'pull --ff-only'

And then tell your users to use it instead of pull:

git update upstream branchname

Upvotes: 1

Related Questions