I just deleted ALL the code from a file in my project and committed the change to my local git (on purpose). I did
git pull upstream master
to fetch and merge from upstream (so in theory that deleted code should be back).
Git tells me everything is up to date.
Everything is definitely NOT up to date -- all that deleted code is still deleted.
I only have one branch called "master".
I recently set up "master" to track upstream like so:
Branch master set up to track remote branch master from upstream.
The command git branch -vv
yields:
* master 7cfcb29 [upstream/master: ahead 9] deletion test
Why why why is this happening? I'm on the verge of just e-mailing my project manager any changes I make to our code.
I thought it was obvious, but anyways this is my goal:
Get the most recent of the code on my system.
Excuse my anger here, but why does such a simple task as that have to be so hard?
Any changes you commit, like deleting all your project files, will still be in place after a pull. All a pull does is merge the latest changes from somewhere else into your own branch, and if your branch has deleted everything, then at best you'll get merge conflicts when upstream changes affect files you've deleted. So, in short, yes everything is up to date.
If you describe what outcome you'd like to have instead of "all files deleted", maybe someone can suggest an appropriate course of action.
Update:
GET THE MOST RECENT OF THE CODE ON MY SYSTEM
What you don't seem to understand is that you already have the most recent code, which is yours. If what you really want is to see the most recent of someone else's work that's on the master branch, just do:
git fetch upstream
git checkout upstream/master
Note that this won't leave you in a position to immediately (re)start your own work. If you need to know how to undo something you've done or otherwise revert changes you or someone else have made, then please provide details. Also, consider reading up on what version control is for, since you seem to misunderstand its basic purpose.
I had the same problem as you.
I did git status
git fetch
git pull
, but my branch was still behind to origin. I had folders and files pushed to remote and I saw the files on the web, but on my local they were missing.
Finally, these commands updated all the files and folders on my local:
git fetch --all
git reset --hard origin/master
or if you want a branch
git checkout your_branch_name_here
git reset --hard origin/your_branch_name_here
Just a friendly reminder if you have files locally that aren't in github and yet your git status
says
Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
It can happen if the files are in .gitignore
Try running
cat .gitignore
and seeing if these files show up there. That would explain why git doesn't want to move them to the remote.
The top answer is much better in terms of breadth and depth of information given, but it seems like if you wanted your problem fixed almost immediately, and don't mind trodding on some of the basic principles of version control, you could ...
Switch to master
$ git checkout upstream master
Delete your unwanted branch. (Note: it must be have the -D, instead of the normal -d flag because your branch is many commits ahead of the master.)
$ git branch -d <branch_name>
Create a new branch
$ git checkout -b <new_branch_name>
As the other posters say, pull merges changes from upstream into your repository. If you want to replace what is in your repository with what is in upstream, you have several options. Off the cuff, I'd go with
git checkout HEAD^1 # Get off your repo's master.. doesn't matter where you go, so just go back one commit
git branch -d master # Delete your repo's master branch
git checkout -t upstream/master # Check out upstream's master into a local tracking branch of the same name
While none of these answers worked for me, I was able to fix the issue using the following command.
git fetch origin
This did a trick for me.
Source: Stackoverflow.com