Integrating Git on your local host
2025-02-08
Integrating your local host machine and code editor with Git enables a seamless workflow for version control and collaboration. In this guide, we'll walk you through the steps to set up SSH keys, clone a GitLab repository, and push changes from your local environment.
Step 1: Generate SSH Key Pair
Run the following command to generate an SSH key pair. The -t ed25519 option specifies the key type, and the -C option adds a comment (usually your email address).
This will prompt you to choose a location to save the key (default is ~/.ssh/id_ed25519), and optionally, set a passphrase for extra security.
Start the SSH agent:
After generating the key pair, run the following command to start the SSH agent, which will manage your SSH keys:
Add your SSH key to the agent:
Next, add the private key (id_ed25519) to the SSH agent. Make sure the path points to where your SSH keys are stored.
Replace the path if necessary.
Step 2: Add the SSH Key to GitLab
Copy the SSH public key:
Use cat to display your SSH public key, and copy the output:
Add your SSH key to GitLab: Go to your GitLab SSH keys page. Paste the copied public key into the "Key" field and give it a descriptive title. Click "Add key."
***Step 3: Test SSH Connection***
To confirm that your SSH key is working, run the following command:
If successful, GitLab will greet you with a message confirming that the authentication was successful.
Step 4: Clone Your GitLab Repository
Now that your SSH key is set up, you can clone your GitLab repository to your local host:
This command clones the specified repository to your local machine, enabling you to work with it.
Step 5: Update and Push Changes to the Repository
Make changes to a file:
Edit a file in your cloned repository as needed. Once you're ready to push changes, follow these steps. Stage changes for commit: Use git add . to stage all modified files:
You can also specify specific files instead of using the dot (.) to stage all files.
Check the status:
Run git status to see which files have been staged for commit:
Commit your changes:
Commit your changes with a descriptive message:
If this is your first time committing, you may need to set your Git username and email globally:
Push your changes:
Finally, push your committed changes to GitLab:
This uploads your changes to the main branch of your GitLab repository.
Conclusion
By following these steps, you can successfully integrate your local server and code editor with GitLab, streamlining your development process. This setup ensures that your code remains versioned and safely stored on GitLab, and you can easily collaborate with others.
Last updated