I've got an out-of-date repo with nothing to add on my machine. I want to pull in the latest stable branch from github.
Should I just clone over it? I'm not sure.
I think you should be able to do a fetch on all the files, then reset them to the origin:
git fetch --all
git reset --hard origin/master
You could probably do it in either order, too.
If you want to remove any files you have added that aren't tracked, do a clean too:
git clean -f
The advantage to this approach over cloning to a new directory is that you will still retain some of the history/ reflog . If you absolutely do not care that data though, then either approach is fine.
I agree with Matt's and meagar's suggestions, but feel I should add a bit to them based on past experiences with using the rm
command in Git projects.
If you are absolutely certain you don't want to keep anything from your directory containing the repo, cd
to the level just above the folder so that you can remove it using git rm
. I've found that using git rm
is just neater than using a plain bash rm
command. From a previous inscidident where I simply removed a file in my staging branch directory, I learnt that doing so threw the whole branch off track just because this wasn't logged in the diff record and if I tried a git commit
it would output "Branch is up to date". A false positive.
Because you want to wipe the files as close to leaving no residual, hard-to-detect, or almost undetectable metadata chunks I'd say a recursive forced removal would be justified here. Ie, if the folder is called MyRepo , simply
git rm -rf MyRepo
then just to double-check what I'd do is simply cd MyRepo
, obviously expecting an error, because the folder shoudln't exist anymore.
Thereafter, proceed to clone your GitHub-hosted version in the same place as before, or anywhere you feel comfortable, and do what you normally do.
只是git pull --all
都应该得到最新的东西。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.