Git add new branch
To create a new branch in Git and add it to the repository, you can use the following commands:
-
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 changes to the files in the new branch:
git add <file-name>
Replace
<file-name>
with the name of the file you want to add to the new branch. -
Commit the changes:
git commit -m "Initial commit"
This will create a new commit with the changes you made.
-
Push the new branch to the remote repository:
git push origin <branch-name>
Replace
<branch-name>
with the name of the new branch. This will push the new branch to the remote repository.
Here's an example of how you can do this:
git branch new-feature
git checkout new-feature
git add file1.txt
git commit -m "Initial commit"
git push origin new-feature
This will create a new branch called new-feature
, switch to it, add a file called file1.txt
, commit the changes, and push the new branch to the remote repository.