Gitlab - 3.2 GitLab branch setup part 2
This second part continues the GitLab branch setup. We will add a small Python file, commit it on the dev1 branch, push that branch to the server, and merge it into main through a merge request.
Adding a file and committing on dev1
From the terminal, enter the project directory and open it in Visual Studio Code with code .. If VS Code is not installed, you can install it via sudo snap install code --classic (or your preferred method). Inside the project, create a simple file hello.py with a single line:
print("hello")
Save it. Back in the terminal, git status shows hello.py as untracked. Stage it and commit:
git add hello.py
git commit -m "add hello.py"
If Git refuses with a missing identity error, configure your user globally:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Then retry the commit. Tracking a new file does not affect the repository in a major way; it just keeps it for reference. The change is not persisted until you commit.
Pushing the dev1 branch with -u upstream
On the GitLab server we still only see main — our local dev1 branch is unknown. A bare git push fails for that reason. We push with the upstream flag so the branch is created on the server and tracked:
git push -u origin dev1
Authenticate with username and password and the push succeeds. Back in the GitLab UI, refresh: there are now two branches. The main branch has only the README, while dev1 also has hello.py.
Opening the merge request
After the push, GitLab shows a "Create merge request" button. Click it, choose dev1 as source and main as target, then "Compare branches and continue". Keep the title and description, uncheck "Delete source branch on merge" if you want to keep dev1 alive after merging, and submit. Logged in as a project Maintainer, you can click Merge to integrate the change. Refresh the project: hello.py now appears on main. That is the first CI/CD principle in action — a single shared repository where modifications are integrated regularly. See you in the next video.