Basic git commands#
In your project directory, there should now be the files from the example project. These are still untracked by git.
In the following, you will use the 4 most basic git commands to transfer the changes from your local repository to GitLab.
Check repository status
Stage changes
Commit changes
Push to GitLab
You can either use Git through the Terminal or through the convenient visual interface of Visual Studio Code.
This section covers the basic workflow in both ways, you should stick to one of them.
Check Repository Status#
Visual Studio Code
Open your project folder in VS Code.
Click the Source Control icon in the Activity Bar (third icon on the left sidebar), or press
Ctrl+Shift+G(Windows/Linux) /Cmd+Shift+G(Mac).The Source Control panel shows: - Modified files under Changes. - Files staged for commit under Staged Changes.
Terminal
git status
Stage Changes#
Visual Studio Code
Hover over a file in Changes and click the + icon to stage it.
To stage all files, click the + icon next to Changes.
Terminal
Add individual files:
git add <filename>
Or add all changes:
git add .
Commit Changes#
Visual Studio Code
Type your commit message in the box at the top of the Source Control panel.
Click the checkmark ✔ to commit staged changes.
Terminal
git commit -m "Describe your change here"
Push to GitLab#
Visual Studio Code
Click the … menu in the Source Control panel.
Select Push.
Your commits will be uploaded to GitLab.
Terminal
git push
Now, open your GitLab project in your browser and verify that the changes have been synchronized. Congratulations, you did your first push!
For more commands, check the GitLab cheat sheet for more commands.
It should be mentioned here, that you can also initialize git repos in your project folder and push them to an empty repository.