Git Push Branch to Github

Git Push Branch to GitHub

Push a branch to GitHub

Let’s create a new local branch, and push that to GitHub.

Start by creating a branch, as we did before:

[user@localhost] $ git checkout -b update-readme

Switched to a new branch ‘update-readme’

Make some changes to the README.md file by just adding a new line.

Check the status of the current branch.

[user@localhost] $ git status

On branch update-readme

Changes are not staged for commit:

(use “git add …” to update what will be committed)

(use “git restore …” to discard changes in the working directory)

modified:   README.md

no changes added to commit (use “git add” and/or “git commit -a”)

README.md is modified but is not added to the Staging Environment:

Example:

Example

[user@localhost] $ git add README.md

Check the status of the branch:

Example

[user@localhost] $ git status

On branch update-readme

Changes to be committed:

(use “git restore –staged …” to unstage)

modified:   README.md

Now, we will commit the changes to the branch:

Example:

[user@localhost] $ git commit -m “Updated readme for GitHub Branches”

[update-readme 836e5bf] Updated readme for GitHub Branches

1 file changed, 1 insertion(+)

Let’s push the branch from the local Git repository to GitHub, where the changes are visible to everyone.

Example:

[user@localhost] $ git push origin update-readme

Enumerating objects: 5, done.

Counting objects: 100% (5/5), done.

Delta compression using up to 16 threads

Compressing objects: 100% (3/3), done.

Writing objects: 100% (3/3), 366 bytes | 366.00 KiB/s, done.

Total 3 (delta 2), reused 0 (delta 0), pack-reused 0

remote: Resolving deltas: 100% (2/2), completed with 2 local objects.

remote:

remote: Create a pull request for ‘update-readme’ on GitHub by visiting:

remote:  https://github.com/webhostguru/hello-world/pull/new/update-readme

remote:

To https://github.com/turtorials-test/hello-world.git

Move to the GitHub, and make a confirmation that the repository has a new branch:

github-push

In GitHub, the changes made can be seen so let’s merge them into the master branch the way we want.

When you click the “Compare & pull request”, you may go through the changes made and new files added: