GitLab Setting Up GitLab Locally with SSH Setup Estimated reading: 5 minutes 20 views Setting up GitLab locally can streamline your workflow and allow you to push and pull code seamlessly from your local machine to your GitLab repository. In this guide, I will walk you through Setting Up GitLab Locally on a Mac with SSH setup. If you already have a new GitLab project created, these steps will help you configure your SSH keys and clone your project locally.By the end of this guide, you will have a fully functional local GitLab setup, allowing you to commit and sync changes effortlessly.Prerequisites for Setting Up GitLab LocallyBefore we dive into the details, ensure you have the following: Mac with Terminal access or Windows with Command Prompt Git installed on your Mac. To check, run: git --version If Git is not installed, install it using Homebrew brew install git A GitLab account and a project created.Setting Up GitLab LocallyGenerate SSH KeysTo securely connect your Mac to your GitLab repository, you need to set up SSH keys. SSH keys help authenticate your system with GitLab without needing a password. Open the Terminal on your Mac. Run the following command to generate a new SSH key pair: ssh-keygen -t ed25519 -C "your_email@example.com" Replace your_email@example.com with your GitLab account email. Press Enter to accept the default file location for the SSH key: /Users/yourusername/.ssh/id_ed25519 When prompted, set a passphrase for added security, or press Enter to leave it blank. Public Key Created New Files GeneratedThis generates two files, id_ed25519 (private key) and id_ed25519.pub (public key) Keygen Files LocationAdd Your SSH Key to the SSH AgentTo ensure GitLab uses the SSH key, add it to the SSH agent: Adding SSH Key To Agent Start the SSH agent by running: eval "$(ssh-agent -s)" Add your SSH private key to the agent: ssh-add ~/.ssh/id_ed25519Add SSH Key to GitLabNow that you have generated an SSH key, it needs to be added to your GitLab account: Generate SSH Key For GitLab No SSH Keys In GitLab Copy your public SSH key by running: cat ~/.ssh/id_ed25519.pub This will display the key in the terminal. Copy the entire key. Log in to your GitLab account and navigate to User Settings SSH Keys . Paste the copied key into the Key field and give it a title. Click Add Key . Adding SSH Key in GitLab SSH Keys SSH Key Added SuccessfullyClone Your GitLab Repository LocallyWith SSH configured, it’s time to clone your project to your local machine. Clone Project Using SSH Key Command In your GitLab repository, click the Clone button and copy the SSH link (it looks like git@gitlab.com:username/project-name.git). Open Terminal and navigate to the directory where you want the project: cd ~/Projects Use the git clone command to clone the repository: git clone git@gitlab.com:username/project-name.git Replace username and project-name with your actual GitLab username and project name. Once the repository is cloned, navigate into the project folder: cd project-name Cloning Project Via SSH Locally Project Available LocallyVerify Your SetupTo ensure everything is set up correctly, run the following commands: 1 Connect with Remote Origin 2 Test SSH 3 Test Commit Check the remote origin, cd to the cloned git project git remote -vYou should see the SSH URL of your GitLab repository.GitLab Verify ConnectionTest your SSH connection to GitLab ssh -T git@gitlab.comIf everything is configured correctly, you will see a message like:Welcome to GitLab, @username!Testing SSH via TermnialCreate a new file in the repository:touch testfile.txtAdd text to file: echo Congrats on creating and pushing your first commit file! > testfile.txtAdd the file:git add testfile.txtCommit the file:git commit -m "Committing test file from local to main"Push the changes:git push origin mainReplace main with your branch name if it differs.Testing The Commit Via Termnial New TestFile.txt Pushed to ProjectConclusionBy following the steps in this guide, you’ve successfully completed Setting Up GitLab Locally on your Mac with SSH setup. Your local environment is now connected to your GitLab repository, making it easy to push and pull code changes securely. With SSH configured, you no longer need to enter your credentials every time, saving you time and effort.Now that your setup is complete, you can focus on coding and collaborating with your team seamlessly. If you encounter any issues, ensure your SSH keys are correctly added to GitLab and your system. Ready to take the next step? Dive into our guide on Managing Projects in GitLab to explore how to organize and collaborate on your projects effectively! GitLab - Previous Getting Started with GitLab Next - GitLab Managing Projects in GitLab