Chuyển tới nội dung chính

Push Branch to GitHub

Hệ thống: MightyLMS - Quản lý giáo dục
Khoá học: Git Tutorial
Book: Push Branch to GitHub
Được in bởi: Người dùng khách
Ngày: Chủ Nhật, 24 tháng 11 2024, 1:26 AM

Table of contents

1. Push Branch to GitHub

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

Start by creating a branch, like we did earlier:

Example

git checkout -b update-readme
Switched to a new branch 'update-readme'

And we make some changes to the README.md file. Just add a new line.

So now we check the status of the current branch.

Example

git status
On branch update-readme
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   README.md

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

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

Example

git add README.md

Check the status of the branch:

Example

git status
On branch update-readme
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        modified:   README.md

We are happy with our changes. So we will commit them to the branch:

Example

git commit -m "Updated readme for GitHub Branches"
[update-readme 836e5bf] Updated readme for GitHub Branches
 1 file changed, 1 insertion(+)

Now push the branch from our local Git repository, to GitHub, where everyone can see the changes:

Example

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/w3schools-test/hello-world/pull/new/update-readme
remote:
To https://github.com/w3schools-test/hello-world.git
 * [new branch]      update-readme -> update-readme

Go to GitHub, and confirm that the repository has a new branch:

GitHub New Branch

In GitHub, we can now see the changes and merge them into the master branch if we approve it.

If you click the "Compare & pull request", you can go through the changes made and new files added:

GitHub Branch Changes

Note: This comparison shows both the changes from update-readme and html-skeleton because we created the new branch FROM html-skeleton.

If the changes look good, you can go forward, creating a pull request:

GitHub Pull Request

A pull request is how you propose changes. You can ask some to review your changes or pull your contribution and merge it into their branch.

Since this is your own repository, you can  merge your pull request yourself:

GitHub Merge Pull Request

The pull request will record the changes, which means you can go through them later to figure out the changes made.

The result should be something like this:

GitHub Merge Confirmed

To keep the repo from getting overly complicated, you can delete the now unused branch by clicking "Delete branch".

GitHub Delete Branch

An after you confirm that the changes from the previous branch were included, delete that as well:

GitHub Delete Skeleton Branch