On my computer science lesson, our teacher asked us to implement a code and I did that part no problem. The part where we have to commit the code to gitlab is the problem for me. Usually I would just commit and after push using git push -u origin master
and after that I would do merge request. But the teacher wants me to not work on master branch. I do not know how am I supposed to work on the new branch I was just copying from the master branch after I pushed. I googled on how to do this but I wasn't really effective searching for this kind of problem.

- 4,222
- 8
- 24
- 34

- 26
- 5
-
`git push -u origin [branch-you-want-to-push]` should help. – Polygnome May 17 '20 at 21:27
4 Answers
For that you have to create another branch from master
and do all your necessary stuffs and then create a pull request
against master
branch to review.
Below are some links to follow

- 1,831
- 3
- 12
- 22
This is what is called branching and merging.
I suggest you to learn about branching and merging with git here.
Here's some tips :
Create a branch and start working on it :
git checkout -b mybranch
You are now working on a new branch called mybranch
(no more in master).
All you commits will be related to this branch.
Push it as you do usually to gitlab with git push
.
Then, you can open a merge request on Gitlab to merge your branch into master.
This post is also related : How to change branch with git.

- 150
- 1
- 7
You can create a new branch that has the same code from the master branch. You can then push changes to this branch and if everything works fine you can then merge with the master. I suppose you are working with GitLab, you can create a new branch by going to your repository and selecting the plus + dropdown symbol.
Hope this helps!

- 1
- 3
I would suggest you, to work with Git Flow (documentation)
A Git Workflow is a recipe or recommendation for how to use Git to accomplish work in a consistent and productive manner. Requirement: you get along with git!
Start with git flow init
(install git flow on your repository)
Then you can create a new feature branch on an existing branch (in your example on master branch -> to reach master branch: git checkout master
) with: git flow feature start feature_branch_name
. After that command, you have a feature branch with the same content as the master branch (or this branch, from which the feature branch was started).
Now you can make changes and push this on the git-server under this feature branch, without touching the master branch. First push with git flow feature publish feature_branch_name
and all others only with git push
.
With git checkout branch_name
you can leave this feature branch and achieve it also with git checkout feature/feature_branch_name
. To list all branches you just enter git branch -a
, so you see also you feature branch name.
If you want to merge the changes from you feature branch to the master, you can close the feature branch with: git flow feature finish feature_branch_name
and all changes will move to master branch (or this branch, from which the feature branch was started) and the feature branch disappears.
Normally, the feature branches will startet on the develop branch. But in your example, it isn‘t important whether from the master or from the develop branch.

- 4,222
- 8
- 24
- 34