How To Commit My Current Changes To A Different Branch In Git

Push commits to another branch

It's very simple. Suppose that you have made changes to your Branch A which resides on both place locally and remotely but you want to push these changes to Branch B which doesn't exist anywhere.



Step-01: create and switch to the new branch B
$ git checkout -b B

Step-02: Add changes in the new local branch
$ git add . //or specific file(s)

Step-03: Commit the changes
$ git commit -m "commit_message"

Step-04: Push changes to the new branch B. The below command will create a new branch B as well remotely
$ git push origin B

Now, you can verify from bitbucket that the branch B will have one more commit than branch A. And when you will checkout the branch A these changes won't be there as these have been pushed into the branch B.

Comments

Popular posts from this blog

Install Ubuntu (20.04.1 LTS) with Windows (Dual boot mode)

How to Mirror Android Screen to Ubuntu(GNU/Linux) Desktop With Scrcpy

Connect GitHub to your machine using SSH