Menu
×
   ❮     
     ❯   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE

Git Push Branch to GitLab


Push a Branch to GitLab

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

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 GitLab branches"
[update-readme 3361404] Updated readme for GitLab branches
 1 file changed, 2 insertions(+)

Now push the branch from our local Git repository, to GitLab, 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), 364 bytes | 364.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for update-readme, visit:
remote:   https://gitlab.com/w3schools-test/hello-world/-/merge_requests/new?merge_request[source_branch]=update-readme
remote:
To https://gitlab.com/w3schools-test/hello-world.git
 * [new branch]      update-readme -> update-readme

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

GitLab New Branch

In GitLab, we can now click the branch, click "Create merge request" to start the process:

GitLab Branch Merge Request

Scroll down to see changes:

GitLab 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 merge request:

GitLab Pull Request

A merge 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 request yourself:

GitLab Merge Pull Request

The merge 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:

GitLab Merge Confirmed


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.