2

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?

orome
  • 45,163
  • 57
  • 202
  • 418

3 Answers3

0

You don't. Or, in other words:

is there a way to configure gtt (with git config) so that git pull overwrites local files every time?

No.

It's worth noting two things here:

  1. git pull is a convenience command that runs two more-basic Git commands for you.
  2. The second command that git pull runs is never an overwrite files command. The first command is an "obtain commits" command, which is git 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).

torek
  • 448,244
  • 59
  • 642
  • 775
0

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
Carlos Marx
  • 496
  • 1
  • 6
  • 13
-3

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.

Bigbrotha
  • 101
  • 1