I noticed while browsing a repo on the Github website that there wasn't a Readme.md file, and Github suggested I make one.  So I did.
After adding the Readme.md file in the web interface, with a commit to a dev branch, I came back to my local repo to pull the Readme down and update to include the latest commit.  I did have some changes in the working directory, but nothing in index.  I needed to change from a different branch, so I stashed the changes and did a checkout on dev. In Git Extensions I could see the remote origin/dev branch one commit ahead, so I ran a git pull to fastforward to the Readme.md commit.  Which all seemed to work.
However, at this point I noticed an issue - a git status shows:
deleted: README.md
So, git knows there is supposed to be a README.md with this commit, but it isn't in the working directory. I checked the wd with windows explorer, and README.md is not in the root directory.  I checked back on Github, and it's there.  I looked in the "File tree" in Git Extensions, and it's also there. But it's not physically on the computer in the folder, and git knows it's not there. I reran git pull and git fetch and tried reading the git fetch --help and git pull --help man pages, and tried a few commands, but nothing will pull down the README.md that I can find.
I could manually download the file and physically place it in the folder, but I want to know how to do this properly. Extra points for an explanation about what happened. Thanks!!
I figured out the issue when LightBender asked in a comment for the full git status, and rather than remove the question, I'll post the root cause and solution here.
Before checking out dev I stashed the changes I had on master, but then I unstashed them on dev, planning to add them to a new commit after pulling down README.md from the remote.
It turns out the stashing somehow realized that master didn't have README.md, so when I applied the stash to dev after the git pull it actually deleted the file. Suspecting this, I restashed the changes and the deletion of README.md disappeared (from git status), and after that a new git pull did correctly pull README.md down from origin/dev into my working directory. I didn't realize that git stash will file away deletions as well as additions and changes...
So, the problem came in because I had stashed the changes originally off of master, and those changes should not have been unstashed on dev in the first place. Being a newbie, I lost track of the flow. It was still good to learn about this behavior for future reference.
I was able to simply unstash (not sure the git commands for unstash - I use Git Extensions for that) back on master, and then cherry-pick the new README.md commit from dev onto master.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With