Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to create and commit a branch in gitlab

Writer Olivia Zamora

This is intended as a question that I answer for other people's benefit. However, if someone answers this question before I finish my research, I would be grateful.

How do I, from the shell, branch an existing git repo (which I have developer access to), edit it, commit those changes then push it to the server for review before being merged.

EDIT

Please note that this is not my project, but someone else's. This use has given me access to do some work. When done, I will request that they merge the changes back to the original

1

2 Answers

For setting up your repo, you will need to follow these instructions. Then you will need to clone/fork the existing repo like this.

Then make your changes. Once you are done making your changes. You will need to make a "commit" that looks like this

git commit -m "I changed something somewhere"

Then you will want to pull down any changes from the repo that may have been pushed while you were working.

git pull origin master // master being the branch that you cloned/forked

Once the pull is completed with no conflicts, you may push your changes up.

git push origin master // this is saying that you want to replace the remote master branch with your local master branch

EDITTo push to a repo without overwriting the master, do this:

git clone //clone what branch you want
git checkout -b new_branch //this will create a new local branch
git push origin new_branch //this will create a new origin branch
8

If I understand your question correctly:

  • You don't have permission to push to the repository
  • You want to create a branch, make some commits, and then propose a merge request

This is actually a perfectly normal situation, here's what to do:

  1. On GitLab, fork the project: this creates a clone of the original repository in your personal workspace. The point is that you can push to your personal workspace.

  2. On your PC, clone from your fork, not the original.

  3. Create a branch (git checkout -b myfeature), make the changes and commit, then push this branch to your fork (git push -u origin HEAD)

  4. On GitLab, visit your fork's page, and near the top there should be a button offering you to create a Merge Request from the branch that you pushed just now. Click on it, review the changes, if it looks good, then set an assignee and click Create. The assignee should receive an email notification

You don't need write access to a project to be able to contribute. All your write operations are on your workspace on GitLab and on your local PC. Reviewers of your Merge Request can accept it or reject as they wish. They can also ask that you make improvements, which you can implement and push (simple git push after your local commits), that updates the merge request (reviewers can reload the page in the browser and see your changes).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy