I understand there are various strategies for forcing Git to completely overwrite the local files from a remote on a per invocation basis, but is there a way to configure get (with git config
) so that git pull
overwrites local files every time?
3 Answers
You don't. Or, in other words:
is there a way to configure gtt (with
git config
) so thatgit pull
overwrites local files every time?
No.
It's worth noting two things here:
git pull
is a convenience command that runs two more-basic Git commands for you.- The second command that
git pull
runs is never an overwrite files command. The first command is an "obtain commits" command, which isgit fetch
. The second command is a "combine obtained commits with current commits somehow" command. The second command is configurable; the first one is not; but no matter which second command you choose, it doesn't mean overwrite.
What this means is that if you want files overwritten, do not use git pull
.
Note that Git is not really about files anyway. What Git is all about is commits. If you aren't interested in using and working with commits (e.g., if you're interested in doing a server deployment), you probably should not be using Git at all here (though many people do use Git as a poor-man's deployment system: it can be pressed into service as one, just as a screwdriver can be used as a chisel, if you need a chisel and all you have is a screwdriver).

- 448,244
- 59
- 642
- 775
The best I can recommend is setting an alias.
That's what I use:
# ~/.config/git/config
[alias]
pf = !"git fetch --all; git reset --hard HEAD; git merge @{u}"
The above alias will discard all local changes. If you just want a pull --force
:
# ~/.config/git/config
[alias]
pf = pull --force --no-rebase

- 496
- 1
- 6
- 13
This is done via
$ git branch --set-upstream-to origin/master
This sets the local branch to track to the upstream remote branch. Git pull should then automatically fetch and merge the branch to your local repo files.

- 101
- 1
-
1How does this answer OP question? – Gaël J Aug 03 '21 at 17:49