
Introduction
Git is the backbone of modern version control, facilitating seamless collaboration and code management across teams. In this blog, we’ll dive deep into the essential Git commands: pull
, add
, commit
, and push
, while also covering how to set up and update SSH keys for secure interactions with your GitLab repository, specifically git@gitlab.com:prafulkr/demo-project.git
.
Git Basics: Pull, Add, Commit, Push
1. git pull
The git pull
command is your go-to for updating your local repository with the latest changes from the remote repository. It effectively combines two actions: git fetch
(to download changes) and git merge
(to incorporate those changes into your current branch).
Syntax:
git pull origin <branch-name>
Example:
git pull origin main
This command updates your local main
branch with the latest changes from the remote repository.
2. git add
git add
is used to stage your changes, preparing them for the next commit. This command essentially tells Git which changes you want to include in your next snapshot of the project.
Syntax:
git add <file-name>
To add all modified files:
git add .
Example:
git add index.html
This stages the index.html
file, making it ready for your next commit.
3. git commit
Once your changes are staged, the git commit
command is used to create a new snapshot of your project. Each commit is a save point in your project’s history.
Syntax:
git commit -m "Your commit message"
Example:
git commit -m "Fixed bug in login functionality"
This records the changes with a message describing what was done.
4. git push
git push
uploads your local commits to the remote repository, making them available to others. It’s the final step in sharing your work.
Syntax:
git push origin <branch-name>
Example:
git push origin main
This pushes your local commits to the main
branch on the remote repository.

Setting Up SSH Keys for GitLab
SSH keys provide a secure way to authenticate with your GitLab repository without using a password. Here’s how to generate, add, and manage your SSH keys for the repository git@gitlab.com:prafulkr/demo-project.git
.
Step 1: Generating an SSH Key
- Create a new SSH key pair:
Open your terminal and run:
ssh-keygen -t rsa -b 4096 -C "social9741@gmail.com"
-t rsa
: Specifies the key type (RSA).-b 4096
: Specifies the key size (4096 bits).-C "social9741@gmail.com"
: Adds a label to the key, often your email.
- Save the key:
When prompted, press Enter to accept the default location (~/.ssh/id_rsa
). - Optionally, add a passphrase:
You can choose to secure your SSH key with a passphrase. If you prefer not to, just press Enter. - Display the SSH key:
cat ~/.ssh/id_rsa.pub
Step 2: Adding the SSH Key to GitLab
- Copy the SSH key:
Use the following command to copy the SSH key to your clipboard:
cat ~/.ssh/id_rsa.pub | pbcopy
- Add the key to GitLab:
- Log in to your GitLab account.
- Go to User Settings > SSH Keys.
- Paste the copied key into the “Key” field.
- Add a descriptive title and set an expiration date if desired.
- Click Add key.
Step 3: Configuring Your GitLab Repository to Use SSH
Ensure your GitLab repository is configured to use SSH:
git remote set-url origin git@gitlab.com:prafulkr/demo-project.git
This command updates your repository’s remote URL to use SSH, enabling secure communication for future Git operations.
Updating Your SSH Key
If your SSH key becomes compromised or expires, you can easily generate a new one and update it in GitLab:
- Generate a new SSH key as shown in the previous steps.
- Replace the old key in GitLab:
- Navigate to User Settings > SSH Keys.
- Remove the old key by clicking Remove next to it.
- Add the new key using the steps mentioned earlier.
- Update your local SSH configuration if needed:
If you saved the new key with a different file name, modify your SSH configuration file (~/.ssh/config
):
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/your_new_key

Conclusion
With these Git commands (pull
, add
, commit
, push
) and SSH key management techniques, you are well-equipped to manage your projects efficiently and securely. This setup ensures that your interactions with GitLab are both effective and protected.
Happy coding!
Tags: Git, GitLab, SSH Keys, Git Workflow, Version Control, DevOps, Software Development