Intellipaat 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!

2 Answers

+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.

0 votes
by (1.2k points)

To create a new branch, add your changes and commit them to the local then push it to remote here is how you go step by step:

Make a new branch and jump to it

Code:

git checkout -b your-new-branch

Adding files

Code:

git add .

This takes you to the stage where now git is tracking changes and staging the files in preparation of the commit

Commit Changes

Code:

git commit -m " your commit message

That is the end of the changes you have made in your local branch.

Push the branch to the remote, so that others can view your changes:

Code:

git push origin your-new-branch.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...