3

I am currently in the process of teaching some of my coworkers Git. They're all artists, and most of them will probably never need to commit files. However it is valuable for them to be able to pull the latest version of the project and test how things look.

Many of them are running into the issue that they last pulled the project a month ago and tested some things out, but when they need to update the project to the latest master they're hit with a bunch of merge conflicts. I want to give them one simple command that they can run that essentially says "I don't care about any of the changes I made, I just want to go back to master" so that they can then do a git pull without errors.

When I've used git, I generally do:

git add -A then git stash

However now that I'm teaching git to others, I want to make sure I'm not steering them down a bad path. I've seen other suggestions of using git reset or git checkout, but is there a generally accepted best way of saying "I don't care about my changes, blast them out the airlock"?

Adam L.
  • 91
  • 5
  • 1
    Have them use a GUI app – pkamb Nov 20 '19 at 23:37
  • Does this answer your question? [How to force a merge to succeed when there are conflicts?](https://stackoverflow.com/questions/36820084/how-to-force-a-merge-to-succeed-when-there-are-conflicts) – abdullahalali Nov 20 '19 at 23:37
  • 1
    There is no need for `git pull` at all here: `git fetch && git reset --hard origin/master` is pretty short and simple. (And highly destructive if they had important changes they wanted to keep!) – torek Nov 20 '19 at 23:46
  • @pkamb yes, I'm realizing that's very important. So far I've tried SourceTree and Git Extensions, but I'm open to suggestions. abdullahalali no, unfortunately not. I don't want them merging changes, generally they'll be ok abandoning them. And torek that actually sounds perfect. Highly destructive is what I'm looking for :D – Adam L. Nov 21 '19 at 00:03
  • @AdamL: I doubt that a GUI is helpful here for non tech user, when you want to restrict user to a few specific "safe" commands. Using a Git GUI still requires said user to understand the Git mental model. If they don't have intuitive understanding of the Git model, a GUI would just make it easy for non tech people to click their way into trouble they won't be able to get themselves out from. I'd suggest writing some [git aliases](https://githowto.com/aliases) for your non tech users, tell them that those are the only commands they should be using. – Lie Ryan Nov 21 '19 at 01:59

2 Answers2

1

If you really want to abandon all local changes, then:

git fetch && git reset --hard origin/master

Note that this won't create a backup of your local changes like your stashing command does, so any local changes will be lost and unrecoverable.

However, a better workflow would've been for the people who do have commit access to avoid creating situations where people pulling from the repository would have to reset their local repo. You do this by making sure that master only moves forward, users cannot force push to master, and by making sure that automatically generated files are in gitignore.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
0
git checkout . && git pull origin master

In detail

Discard the latest changes: git checkout .

Receive changes from the master origin: git pull origin master

tailot
  • 9
  • 1
  • 4