Git – working on wrong branch – how to copy changes to existing topic branch
Top of Google is”working on the wrong branch” to checkout the branch to be working on. No need to hoard anything:
git checkout branch123
Checkout the modified file to stop overwrite the working directory,
Update : This method will work when the files is modified in the working directory for both master and branch123.
his scenario works at least with VS 2015 Git plugin but would most likely work with any git tool.
- checkout and make changes to files in master (ups!, wrong branch)
- create a new branch “temp” (or any unused name you choose) from master. Checked out files will now be checked out in temp and not in master.
- check in changes to temp (master is untouched)
- Everything is now checked in and it is possible to check out an existing branch. Check out the wanted branch (the branch I wanted to make the changes to begin with) 3.5 Git Rebase
- merge temp to the wanted branch. Now the changes are in the correct branch.
- delete the temp branch as it is not needed any more