How to push to a new branch
To push your local branch to a new branch on a remote repository, you can use the following Git commands:
- Create a new branch:
git branch <branch-name>
Replace<branch-name>
with the name you want to give your new branch.
Example: git branch feature/new-login-system
- Switch to the new branch:
git checkout <branch-name>
This will switch your local repository to the new branch.
Example: git checkout feature/new-login-system
- Make changes and commit them: Make the changes you want to commit, then commit them using
git add
andgit commit
.
Example:
git add.
git commit -m "Initial commit for new login system"
- Push the new branch to the remote repository:
git push -u origin <branch-name>
This will create a new branch on the remote repository and set the upstream tracking information.
Example: git push -u origin feature/new-login-system
The -u
flag sets the upstream tracking information, which allows you to use git pull
and git push
without specifying the branch name.
- Verify the new branch: Use
git branch -a
to verify that the new branch has been created on the remote repository.
Example:
git branch -a
* feature/new-login-system
master
remotes/origin/feature/new-login-system
remotes/origin/master
Now you can work on your new branch, make changes, commit them, and push them to the remote repository as needed.