I want to sync my local repository so as to make the local an exact copy of the master. Since checking it out I have added several files to my local, not present in master, that I do not wish to commit. Nevertheless, in this procedure, I want to erase all differences of my local from master: when I am done, the additional files in local will have been deleted.
An earlier question offers a strategy to make local like master: Reset local repository branch to be just like remote repository HEAD
But this does not work for me. The recommended commands, git fetch origin git reset --hard origin/master
do not erase the additional files from my local, even though git status indicates local and master are identical. And also, in one case the master's version of a file did not replace my local version.
Any ideas on how to do this?
Actually, the commands you tried will reset all tracked files to the state of origin/master
. However, git doesn't touch untracked files (usually). In fact, the whole purpose of the "untracked file"-feature is, to be able to have file completely independent of git inside the repository.
However, you can still make git delete untracked files if you want to:
To delete all untracked files from your repository, type:
git clean -f
(Source: How to remove local (untracked) files from the current Git working tree?)
Be aware, as the files you delete are untracked, they will be lost forever.