Git is a Version Control System, but what does that actually mean? When developers create something (like an app), they make constant changes to the app, releasing newer versions. The version-control system keeps these revisions straight, storing the modifications in a central repository. This allows developers to easily collaborate, as they can download a new version of the software, make changes, and upload the newest revision. Every developer can see these new changes, download them, and contribute.
Here is the three-stage architecture of Git
Some Important Terms here are:-
Repository — A repository is a place where you have all your code. You can think of it as a folder on the server. It is kind of a folder related to one product. Changes are personal to that particular repository.
Server — It stores all repositories and contains metadata as well.
Working Directory — This is where you see the files physically and do the modifications.
Commit — It stores changes in the repository. You will get an alphanumeric commit ID.
Tags — Tags assign a meaningful name with a specific version in the repository.
Push — Push operations copy changed from a local repository server to a remote/central repository. This is used to store the changes permanently in the Git Repository.
Pull — Pull operation copies the changes from a remote repository to a local machine. The pull operation is used for synchronization between the repository.
Basic Git commands
Here are some basic GIT commands you need to know:
git init will create a new local GIT repository. The following Git command will create a repository in the current directory:
git clone is used to copy a repository. If the repository lies on a remote server, use:
git clone <repository_url>
git add is used to add files to the staging area. For example, the basic Git following command will index the temp.txt file:
git add <temp.txt>
git commit will create a snapshot of the changes and save it to the git directory.
git commit –m “Message to go with the commit here”
set global username and email for git (Locally)
git config --global user. name "<your username>" git config --local user.email "<youremail>"
git checkout creates branches and helps you to navigate between them. For example, the following basic command creates a new branch and automatically switches you to it:
command git checkout -b <branch-name>
To switch from one branch to another, simply use:
git checkout <branch-name>
git remote lets you view all remote repositories. The following command will list all connections along with their URLs:
git remote –v
To connect the local repository to a remote server, use the command below:
git remote add origin <host-or-remoteURL>
Meanwhile, the following command will delete a connection to a specified remote repository:
git remote rm <name-of-the-repository>
git branch will list, create, or delete branches. For instance, if you want to list all the branches present in the repository, the command should look like this:
If you want to delete a branch, use:
git branch –d <branch-name>
git pull merges all the changes present in the remote repository to the local working directory.
git merge is used to merge a branch into the active one.
git merge <branch-name>
git diff lists down conflicts. In order to view conflicts against the base file, use
git diff --base <file-name>
The following basic command is used to view the conflicts between branches before merging them:
git diff <source-branch> <target-branch>
To list down all the present conflicts, use:
git tag marks specific commits. Developers usually use it to mark release points like v1.0 and v2.0.
git tag <insert-commitID-here>
. git status shows the status of your git repository
Hope you liked this basic introduction to Git also known as Distributed Version Control System. If you liked my article, please give your claps and follow me. Thank you! 🙏