GIT (GitLab) — How to configure Git on macOS, connect to a remote repository, create a new branch, and merge into the main branch from the Terminal Command Line.

Mert Kadir Gursoy
2 min readJul 4, 2021

--

Git Configuration: (MacOS)

  1. Open the Terminal and check if Git is installed:
git --version

2. If Git is not installed, install Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3. Then, install Git:

brew install git

4. Check if Git is successfully installed:

git --version

5. Check the Git account configuration:

git config --global --list

6. If there is a configuration and you want to reset it:

git config --global --unset-all user.name
git config --global --unset-all user.email

7. If the Git identity does not exist, configure it:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

8. Check the Git account configuration again:

git config --global --list

Adding Your Project to GitLab:

  1. Navigate to the project directory:
cd desktop/yourProjectFolder

2. Initialize the project directory with Git:

git init

3. Link to the remote repository (created on GitLab):

git remote add origin https://gitlab.com/YourGitLabUsername/YourProjectFolder.git

4. Check the remote configuration and connection:

git remote -v

Bonus: If a repository already exists, you should remove it first.

git remote remove origin

5. Pull the files from the remote repository:

git pull origin main

You should’ve seen pulled files in your folder.

6. Drag & Drop your project files from your local project folder to this new “yourProjectFolder”

7. Add all files to the “staging” area:

git add .

8. Commit the changes:

git commit -m "Initial commit"

9. Push the changes to the main branch on the remote:

git push origin main

Now, check your gitlab project repository. It should be already up to date.

Adding a New Feature (Creating a Branch):

  1. Create and switch to a new branch:
git checkout -b feature-branch-1

2. Create a new feature file:

 touch new_feature.js

3. Add the file to the “staging” area:

git add new_feature.js

4. Commit the changes:

git commit -m "Added a new feature to feature-branch-1"

5. Push the changes to the remote feature branch:

git push origin feature-branch-1

Updating the Main Branch (Merge):

  1. Switch to the main branch and pull from the remote:
git checkout main
git pull origin main

2. git merge feature-branch-1

git merge feature-branch-1

3. git merge feature-branch-1

git push origin main

That’s all you need for now.

Bonus - Checking the difference:

  • Select your folder with cd command
cd desktop
cd yourProjectFolder
  • Check the status of it
git status
  • Then check the difference
git diff

--

--

Mert Kadir Gursoy
Mert Kadir Gursoy

Written by Mert Kadir Gursoy

Product Team Lead | Product Management ~ Product Design ~ UX Research ~ Technical Project Management

No responses yet