1

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.

So my question is:

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?

torek
  • 448,244
  • 59
  • 642
  • 775
SPQRInc
  • 162
  • 4
  • 23
  • 64

1 Answers1

1

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
padawin
  • 4,230
  • 15
  • 19