Why can't I switch branches, when trying to use "git checkout" in Visual Studio Code
·
Answer a question
I've been working on a website using Visual Studio Code. I've branched off of main this weekend on a desktop. I pushed all of the changes to the remote.
Later on my laptop, where I thought I had the main branch cloned, when I tried running the command git checkout, but it didn't find anything branches. I'm still new to using Git so I'm sure I've done something wrong, but don't know what. What am I doing wrong?
Answers
Here are the things you should consider before using git checkout:
- Check if you changed something, you can do that by the command:
git status - If you did changed something, you can either
commitorstashthe changes.stashremoves all your changes made.commitadds all your changes (affects only your branch).
- If you choose to remove the changes, you can simply use the command:
git stash - If you choose to add the changes. Do the following command:
git add .adds all your changes.git commit -m 'Hey I changed something'commits the changes to your `local branch
After that, you can now use git checkout. Note, by the time you checkout, all the changes you committed under your branch will be pushed to where you checked out.
I hope it helps.
更多推荐
所有评论(0)