Follow the documentation from the official website [here].
Installation on Ubuntu
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
git --version
Add SSH key to GitLab
First generate SSH keys from your Linux CLI for seamless and secure interaction with Gitlab servers.
ssh-keygen -t rsa -b 2048 -C "[email protected]"
cat .ssh/id_rsa.pub | clip
- Navigate to https://gitlab.com and sign in.
- Select your avatar in the upper right corner, and click Settings
- Click SSH Keys.
- Paste the public key that you copied into the Key text box.
- Make sure your key includes a descriptive name in the Title text box, such as Work Laptop or Home Workstation.
- Include an (optional) expiry date for the key under “Expires at” section.
- Click the Add key button.
Testing
ssh -T [email protected]
You should receive a Welcome to GitLab, @username! message.
Perform Git Operations
Clone a repository to local
git clone [email protected]:vaibhav-ml/public.git
Convert a local directory into a repository
When you have your files in a local folder and want to convert it into a repository, you’ll need to initialize the folder through the git init command. This will instruct Git to begin to track that directory as a repository. To do so, open the terminal on the directory you’d like to convert and run:
git init
This command creates a .git folder in your directory that contains Git records and configuration files.
Add remote repository
git remote add origin [email protected]:vaibhav-ml/public.git
Pull latest changes from remote to local
git pull <REMOTE> <name-of-branch>
git pull origin master
git remote -v
Add all changes to commit
git push --set-upstream [email protected]:vaibhavsingh-com/public.git master
git add .
git commit -m "DESCRIBE THE INTENTION OF THE COMMIT"
Send changes to Gitlab.com
git push <remote> <name-of-branch>
git push origin master
git remote -v
Summary
That’s all. If the above steps are followed in sequence, we’d have an environment to interact with Gitlab repo from local linux cli.
Remember to always cd
to local git directory and execute git pull origin master
when beginning work on local to ensure you have the latest copy.