Reputation: 479
( Being new ,i am not claiming that its not working correctly , obviously there's issues with my understanding , hence the word expected ) ...
Lemme explain properly.... Lets say i clone a git repo which has 10 files inside it.
Currently as i have just cloned , both my local copy and github repo are exactly same.
I now do two changes - One in my github repo and other in my local copy. eg. A) I added file 11 and 12 in my github repo . B) I delete file 9 from my local copy .
Now i want my local copy to get synced with my github repository such that it exactly mirrors it ( basically that same state if i would have deleted my local copy and recloned it )
ie A) it should add new files 11 and 12 from git repo B) it should bring back file 9 present in git repo
After googling a bit , i found that we can use git pull origin master to update our local copy of repo But running that said - already up to date...
git remote -v had the remote -origin pointing to my github repo so that's absence of remote is not the issue..
I guess i am missing something. What would be the proper command to acheive the 2 tasks that i mentioned above .
Upvotes: 0
Views: 5191
Reputation: 212634
To reset the local repo to match the remote, while discarding any uncommitted changes (and potentially orphaning some commits, so that they might be discarded by a future garbage collection), you could do:
git fetch origin
git reset --hard @{u}
The first command retrieves the commits from the remote, and the second resets the local repository to make it match the remote.
Upvotes: 3
Reputation: 154
I have a few questions:
1 : What do you mean by added 2 files in git repo?
2 : Have you done "git add filename" ?
3 : Do you mean there are a few new files present in your repo after you cloned it?
According to my understanding first you have to add your changes, i.e deletion of file9 by using command -
git add 'file name'
git commit -m "comment"
git push
And then - git pull origin master OR git merge
Now it will show new additions to your repo, or merge conflicts.
You have to resolve these merge conflicts in order to sync your branch with repo.
Upvotes: 0