I got a git repository containing a main
-branch.
Unfortunately I created a lot of new features there and committed the changes, but I did not push them yet.
Now I'd like to work on another computer, so my idea was to create a new branch from the committed, but unpushed changes on main
.
How to create a new branch called version3
containing all those unpushed changes from main
and remove those commits from main
after that to get a main
-branch that does not contain the new features until I merge them?
You can do the following:
# Create a new branch `version3` based on `main` and check it out
git checkout -b version3 main
# Push `version3` (-u to make the local branch track the remote branch)
git push -u
# Go on `main` and remove the commits you do not want
git checkout main
git reset --hard origin/main
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.