In this article we are going to cover How to Create SSH Key in Git, How to Add SSH key to GitLab, Clone Gitlab Repo with SSH and Push Local code to GitLab repository.
What is SSH Key ?
SSH stands for Secure Shell. And it is authenticates to the GitLab server without using username and password each time. And before creating SSH Key you need to install Git on your machine.
Follow below link install git client on Windows or Linux OS
Step #1: Open the Git Bash and run the command to run generate SSH key in Git
Step #2: Now go to GitLab.com and login to your GitLab account and click on profile, click on Edit Profile
Step #3: Now click on SSH Keys at left side of menu
Step #4: Go to C:\ drive, click on .ssh folder and open the file with .pub extension and copy the SSH key
Step #5: Add SSH key to GitLab Profile
Step #6: Now click on Add key button and add SSH key in GitLab
Here you can see our SSH Key has been created successfully.
Step #7: How to Clone Gitlab Repo with SSH
Before Push code firstly you have to config the username and email as shown in below
git config --global user.name "devopshint"
git config --global user.email email@example.com
git config –list
Open Git Bash and run the command git clone and your clone with SSH same as shown below
git clone firstname.lastname@example.org:devopshint/demo.git
List the repo if it is cloned on your system
Step #8: Push Local code to GitLab Repo
Navigate to git repo
Create one file or copy any file that repository folder for creating file run the command touch and filename
then run the command git add .
Run the command git commit –m “you can assign any commit here”.
git commit –m “you can assign any commit here”
Run the push command git push –u origin main(main is the branch name if your branch name is master then you have to run the command main)
We have covered How to Create SSH Key in Git, How to Add SSH key to GitLab, Clone Gitlab Repo with SSH and Push Local code to GitLab repository