Physical Address
Metro Manila, Philippines
Physical Address
Metro Manila, Philippines
An open-source distributed version management system is called Git. On top of Git, GitLab was developed. In GitLab, you may easily do various Git activities and the git command line is necessary for more difficult activities, such as fixing tricky merge conflicts or rolling back commits. This article is for beginners and new to Git, you will learn some basic git commands that you may use to boost your work efficiency, tracking codes, team collaboration and extending this feature using Gitlab.
You might need to input your credentials when starting git from your computer to prove that you are the author of the work. You should use the same username and email address as you use in GitLab.
Add your user name and email address
git config --global user.name "your_username"
git config --global user.email "yo****************@ex*****.com"
Check your current configuration:
git config --global –-local
You may select any project you have and must have permission to access on GitLab.com
1. Go to the GitLab Repository and click on Clone
2. Copy the HTTPS/SSH Clone URL by clicking on the copy button on the right of the URL
Example Repository Clone URL:
Clone with SSH
https://gitlab.com/rockitpinnoy/webcodes
Clone with HTTPS
gi*@gi****.com:rockitpinoy/webcodes.git
Cloning Repository
git clone <repo> <directory>
When you clone a repository, your computer downloads the files from the remote repository and establishes a connection.
This connection requires you to add credentials. You can either use SSH or HTTPS. SSH is recommended.
Lets assume that we have already configured Gitlab SSH Authentication, if you haven’t done this before you may follow the official guides on Gitlab SSH Documentation
Clone with SSH
git clone gi*@gi****.com:rockitpinoy/webcodes.git
Or this way around
Clone with HTTPS
git clone https://gitlab.com/rockitpinoy/webcodes.git
Go to the newly created directory webcodes:
cd webcodes
Note: A separate window will appear on screen requesting for your Gitlab Credentials, just provide them to authenticate then your are good to go.
You can initialize a local folder so Git tracks it as a repository.
git init
A .git folder is created in your directory, this folder contains Git records and configuration files. You should not edit these files directly.
Add Remote
You add a “remote” to tell Git which remote repository in GitLab is tied to the specific local folder on your computer. The remote tells Git where to push or pull from.
git remote add origin gi*@gi****.com:rockitpinoy/webcodes.git
View Remote
To view your remote repositories, type:
git remote -v
The -v flag stands for verbose.
Download Updated Data
git pull
When you clone a repository, REMOTE is typically origin. The repository on the remote server provides the location from which it was cloned, indicating either an SSH or HTTPS URL.
git checkout -b <branch>
Branch names cannot contain empty spaces and special characters. Use only lowercase letters, numbers, hyphens (-), and underscores (_).
To switch to an existing branch:
git checkout
For example, to change to the main branch:
git checkout main
To view the differences between your local unstaged changes and the latest version that you cloned or pulled:
git diff
To check which files have been changed (added, changed, or deleted files or folders)
git status
git add git status git commit -m "YOUR COMMIT DESCRIPTION HERE"
As a shortcut, you can add all local changes to staging and commit them with one command:
git commit -a -m " YOUR COMMIT DESCRIPTION HERE"
To push all local changes to the remote repository:
git push
Example: push local commits to the main branch of the origin remote:
git push origin main
git checkout .
git reset
Undo Recent Commit
To rewind history without changing the contents of your local files
git reset HEAD~1
When you are ready to add your changes to the default branch, you merge the feature branch into it:
git checkout git merge
Fetch Repository
git fetch <remote name>
Updates your remote-tracking branches under refs/remotes//.
Example: This operation is safe to run at any time since it never changes any of your local branches under refs/heads.
git fetch origin
git pull <remote> <branch>
Brings a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.
Example: Fetch changes from the branch main in the remote called origin.
git pull origin main
References: