Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

I just made changes to a branch. My question is, how can I commit the changes to the other branch?

I am trying to use:

git checkout "the commmit to the changed branch" -b "the other branch"

However, I don't think this is the right thing to do because in this case, I'm creating a new branch instead of committing the changes to "the other branch".

Should I use the following command instead?

git merge "the other branch"

Thanks in advance!

1 Answer

+1 vote
by (62.9k points)

git checkout -b your-new-branch

git add <files>

git commit -m <message>

Firstly, you need to check out on your new branch. Secondly, you add all the files into the staging area which will next be ready to get committed, which means by adding the file it will now be tracked by git. Lastly, commit all the files you just added. You might want to do a 

git push origin your-new-branch

 afterwards, so your changes show up on the remote.

Browse Categories

...