To publish a branch in GitHub, you need to push it to a remote repository. Here's how:
- Create a local branch: Use
git checkout -b <branch_name>
to create a new branch and switch to it. - Make changes and commit: Make the necessary changes to your code, stage them with
git add .
, and commit withgit commit -m "Your commit message"
. - Push to the remote: Use
git push origin <branch_name>
to push your local branch to the remote repository.
For the first push of a new branch:
- Use
git push origin -u <branch_name>
to set the upstream branch, which creates a tracking relationship between your local and remote branches.
Example:
Let's say you want to create a new branch called feature-x
and push it to a remote repository named origin
. Here's how you would do it:
git checkout -b feature-x # Create a new branch called 'feature-x' and switch to it
# ... Make changes to your code, stage, and commit ...
git push origin -u feature-x # Push the branch and set the upstream
By following these steps, your branch will be published on GitHub and available for collaboration with others.