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

Time:11-12

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.

CodePudding user response:

You can use:

$ git reset --hard

Or stash and discard your stashes changes:

$ git add .
$ git stash
$ git stash clear

CodePudding user response:

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

  • Related