Commit to new branch
A Git command!
To commit changes to a new branch, you can follow these steps:
-
Create a new branch:
git branch <branch-name>
Replace
<branch-name>
with the name you want to give your new branch. -
Switch to the new branch:
git checkout <branch-name>
This will switch your current branch to the new one.
-
Make your changes and commit them:
git add <file-name> git commit -m "Initial commit"
Replace
<file-name>
with the name of the file you want to commit, and replace"Initial commit"
with a meaningful commit message. -
Verify that your changes are committed:
git log
This will show you a log of all your commits, including the new one.
That's it! You've committed your changes to a new branch.
Example:
$ git branch new-feature
$ git checkout new-feature
$ git add file1.txt
$ git commit -m "Initial commit"
$ git log
This will create a new branch called new-feature
, switch to it, commit a file called file1.txt
, and then show you a log of all your commits.