0

I would like to "self-update" my php app with git. The app should fetch the latest code from the remote repository (github) and overwrite the local code.

It should do the following:

  • Fetch the latest code from remote (only master branch)
  • overwrite the local code (including any unstaged changes)
  • it must not overwrite/delete anything listed in gitignore
  • it should show a diff of all the files that have changed (for logging purposes)

At the moment i'm using the following commands:

git fetch origin master
git diff master origin/master --stat
git reset --hard origin/master

This works, as it fetches the latest code from the remote and overwrites all the latest changes. The problem is, that git diff also shows some old changes and I need it to show just the latest changes.

peeebeee
  • 2,541
  • 6
  • 21
  • 26
David
  • 1
  • 1
  • What do you mean by 'old changes'? That command should only show the changes since the last time you updated. Are you making local changes as well? If you just want the latest commit, you could use `git show origin/master`. – Holloway May 15 '19 at 09:51
  • Hi, thanks for your answer.Let's say i changed file `a.php` on the remote and did all the commands listed above. `git diff` shows that file `a.php` has changed. So after that lets say I changed file `b.php` on the remote and run those commands again. Now `git diff` shows the files `a.php` & and `b.php`. The changes of file `a.php`have already been integrated the last time I ran the commands. – David May 15 '19 at 09:55
  • Which branch is the local repo on? – Holloway May 15 '19 at 09:58
  • Thanks for the hint, this was the problem. The local repo was not on master branch (don't know why excactly). I added `git checkout --force master` at the beginning of the script and this solved the problem. – David May 15 '19 at 10:29

0 Answers0