I have a repository having two branches master ( keeps final error free code ) and develop ( developing branch ).The default branch is master, I cloned and worked on the project, but unfortunately I forgot to checkout to the develop branch before I start coding.So all the changes that I made will be on the master branch. Is there any way to switch the branch after developing? so that I can commit and push the code only to the develop branch without loosing my code.
Asked
Active
Viewed 1,216 times
2
-
1Just do `git branch new-branch` to create a new branch at your current HEAD and then reset the `master` back to where you want it. (eg, `git branch new-branch; git reset --hard @{u}; git checkout new-branch`) – William Pursell Feb 11 '22 at 13:30
2 Answers
1
If you don't have any work saved on your develop branch, just delete it with git branch -d develop
and rename master to develop with git branch -m master develop
.
If you have something already on your develop, just merge the changes into develop with git checkout develop
then git merge master
.

walgarch
- 21
- 5
-1
git fetch origin master
git checkout main
this command will switch your branch

Hu Zhi Xing
- 148
- 14