Skip to content

Something Went Wrong!

Darren edited this page Mar 24, 2026 · 1 revision

Git is great, but it is easy to overlook something and make a mistake.

Here are some quick fixes for common issues you might experience:

I accidentally made my changes on the main branch but haven't committed them yet

If the branch you want to move your changes to already exists, run:
git checkout main
git stash
git checkout <existing-branch-name>
git stash pop

If you want to move the changes to a new branch, you can run this useful one-liner:

git switch -c <new-branch-name>

I accidentally made my changes on the main branch and committed them

In this case, you won't be able to move your changes to an already existing branch.
Otherwise, create a new branch from main which includes your changes and then reset main:
git checkout -b <new-branch-name>
git checkout main
git reset --hard HEAD~1
git checkout <new-branch-name>

IMPORTANT NOTE - if you've committed more than once on main, you'll need to replace HEAD~1 with HEAD~n where n is the number of commits you've made

I've made some changes that I want to push to the repo and other changes that I don't want to keep

In the source control sidebar panel (the icon is three dots connected by lines), you will see all of the changes you've made.
You can right-click on any of these and select 'Discard Changes'
This will completely remove your changes, so make sure you don't want them before doing this!

I want to work on multiple changes/fixes at once!

You can create multiple branches for different fixes and they will all be isolated from each other.
Just make sure to use checkout commands or the console to switch to the relevant branch before you make changes.

Clone this wiki locally