简体   繁体   中英

How to checkout/switch to remote branch and create local copy while discarding local changes?

I want to checkout a remote branch, create a local copy and pull/update with current remote branch while at the same time ignore changes to the currecntly selected local branch(a different branch)?

I dont want to stash my changes to the current local branch. I want to discard them, pull new branch localy nad checkout.

I tried this command but it keeps asking me to stash my local changes from the current branch:

sudo git switch -c fix/my_branch origin-http/fix/my_branch

this is the message I get:

error: Your local changes to the following files would be overwritten by checkout:
    my_local_file.txt
Please commit your changes or stash them before you switch branches.

You can use:

$ git reset --hard

Or stash and discard your stashes changes:

$ git add .
$ git stash
$ git stash clear

The other answer works as well but this solution I found seems more concise:

sudo git switch -cf fix/my_branch origin-http/fix/my_branch

simply adding the -f parameter in the git switch

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM