2

There're two remote repos on github:

repo_course: course instructor regularly release new assignment skeleton code;

repo_me: my own with completed assignment code to grade;

It works like that:

git clone <repo_me url>: create local working repo on my computer which is empty

git add remote skeleton <repo_course url>

git pull skeleton master: fetch skeleton code, complete it, and push to repo_me

My question is:

Suppose that I pulled skeleton.java and rename or delete it, then I git pull skeleton master again, it won't restore. Why is that? It seems pull will add the new skeleton files only once at the first pull since last time. What's the benefits of its being designed like this?

What should I do if I indeed need to restore my deleted files from repo_course?

2
  • 5
    git pull means git fetch && git merge: obtain their new work, then combine it with your work. So: Why do you believe Git should undo your work? You removed the file. He didn't touch the file. Git keeps your change. Commented Mar 6, 2018 at 5:18
  • very enlightening, thanks! Commented Mar 6, 2018 at 11:31

1 Answer 1

1

If you want your work replayed, instead of their work merged, try (with Git 2.9 or more):

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

Then a simple git pull will replay (rebase) your local commits (including your file rename) on top of what you are fetching.

"Why git pull doesnt' restore deleted files?

Because a merge would override local modification (like the file rename) with what is merged.
As opposed to rebase, which will rebase your own local work (like a file rename) on top of what is fetched.

Sign up to request clarification or add additional context in comments.

5 Comments

I'd 'copy' torek's comment before before it clearly says why it doesnt work as expected by OP
@Daij-Djan it will here: I changed the meaning of git pull, which in my case means fetch + rebase, not fetch + merge.
-1 sorry I dont get your comment and while this is awesome advice I miss the answer to the question: "Why git pull doesnt' restore deleted files?"
@Daij-Djan Sure: I have edited the answer for you to cancel your downvote.
looks better :) im still saying toreks commment was clearer but nvm :) thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.