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.

  1. Check repository status

  2. Stage changes

  3. Commit changes

  4. 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

  1. Open your project folder in VS Code.

  2. 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).

  3. The Source Control panel shows: - Modified files under Changes. - Files staged for commit under Staged Changes.


Terminal

git status

Stage Changes#

Visual Studio Code

  1. Hover over a file in Changes and click the + icon to stage it.

  2. 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

  1. Type your commit message in the box at the top of the Source Control panel.

  2. Click the checkmark to commit staged changes.


Terminal

git commit -m "Describe your change here"

Push to GitLab#

Visual Studio Code

  1. Click the menu in the Source Control panel.

  2. Select Push.

  3. 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.