0

I am the sole developer on my own projects and my workflow is the following:

  1. Local development, committing and pushing to github repo.
  2. SSH into web server where I do

git add -A

git stash

git pull origin master

Now, if I don't stash every time before I pull the master branch head, it will end with "aborting", because some file would be overwritten otherwise. This causes lots and lots of stashes, that I will never need.

How can I make git understand that the code I pull is always the code that I want? If there is something that will be overwritten by the pull, so be it.

Community
  • 1
  • 1
ToJo_195
  • 51
  • 1
  • 9
  • 1
    Why is there anything that needs to be 'added' if you're the sole developer of the project? Local development -> push -> SSH into server -> pull -> done, is what I'd do. –  Mar 24 '19 at 19:15
  • 1
    Why don’t you just pull BEFORE making your changes? If you’re the sole developer, then you should know if there are unpulled changes out there. Throwing away your changes when you pull doesn’t make much sense, and working off a stale branch isn’t ideal. The only time you even need to stash before pulling is if you’ve modified a file that is also modified upstream. And the only time a file is modified upstream is if you (the sole developer) pushed a commit from another computer. This feels like a nonissue and like you should develop better habits. – Nate Mar 24 '19 at 19:18
  • If your issue is pulling when deploying, then the answer is — stop modifying files on a production server. If you have no changes on the server, then you’ll have no conflicts on pull. Likewise, if you have no changes on the production server, there will be no changes to stash. – Nate Mar 24 '19 at 19:21
  • I'm guessing that on the production server some files are altered by running the app (or something similar). If you run git status on the server, do you see any changes? – DaveShaw Mar 24 '19 at 19:24
  • 1
    @DaveShaw then these files should probably be git ignored. – Nate Mar 24 '19 at 19:24
  • Okay guys, this was obviously a stupid question, downvote and all, I will just keep doing `git stash clear`after my pulls and not bother anyone with questions. Sorry for my ignorance. DaveShaw: thanks for the tip, I will check the status next time. – ToJo_195 Mar 24 '19 at 19:50
  • @ToJo_195 it’s not a stupid question. People here forget what it’s like to not know something. – evolutionxbox Mar 24 '19 at 23:34

2 Answers2

1

Since Git 2.6, I generally set:

git config --global pull.rebase true
git config --global rebase.autoStash true

That way, I don't think anymore about stashing: it is done for me be the rebase part of the pull (since I prefer to do a pull --rebase by default)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

As far as I know, you have delete the local repo and reclone it from the origin. Then checkout the branch or commit you want.