- April 13, 2020
- Posted by: Tanvir
- Category: Blogs
Git SCM was invented by Linus Torvald, the creator or Linux in 2005. These commands are used to develop commercial and non-commercial projects as well as for managing repositories. It is an open-source Version Control System (VCS) tool. This tool is designed to handle every type of project in the software and Information technology sector so that it can track the changes made in the file. Despite handling all types of projects, Git commands have maintained its speed and efficiency at the top. Earlier we used to keep track of the work process to make a copy of changes made in the file but, after version control was introduced, we could professionally manage our work and folders. Also, it helped in restoring the previous version of project work by storing the last work on GITHUB, its local repository. Git command line is a set to help developers with a high-level operation. Also, providing full access to internals. Git command line is also used by software programmers to collaborate on software development and applications.
Advantages of Git Commands
One of the best benefits/advantages of Git commands is branching capabilities. Git branches are cheap to buy and will take hardly any effort to merge. This feature is trending among every Git user. The main advantage of this is to provide an isolated environment for every change in the codebase.
How to Set Up and Use GIT Command-line?
- Set up a username and email id in the main configuration file
- Initialize a Git repository. This setting will help the user in creating new projects or modify the existing one
- We use Git Commands to copy repository from a remote source and also get the remote reference to the original position and set it over there.
- Checking your file status that you have changed while working
- Make changes in your working directory
- You can save those changes that you don’t want to apply immediately
- Merge two branches
- Adding new remote repository
How Do You Set Up GIT Command-line Locally?
b. Check whether the Git command line is properly installed in your system. To verify it, open a new shell and type git –version
c. Now, set up your email and Id and Git Username
i. Syntax: git config – -global user.name “YOUR_USERNAME”
d. Verify your username
i. Syntax: git config – -global user.name
e. Set up your email address
i. Syntax: git config – -global user.email email@example.com
f. Verify your email address
i. Synatx: git config – -global user.email
The above process is the one-time process as we are using the “global” option. As per project demands, if a developer wants to run it with a different username and different email id’s, then use the commands without –global option.
Let us view the information you have entered in a project
Syntax: git config –global –list
Basic Setup for GIT Command-line
- The basic flow of using Git is as follows:
- In the root directory or a sub-directory, create a new file.
- You can update the existing file as well.
- Add files to the staging area. This addition can be done by using the “git add” command and passing the necessary options.
- Commit files to the local repository using the “git commit -m <message>” power.
Here are Some Important GIT Commands You Need to Know:
- git init: it creates a new local Git repository.
- git clone: It is used to copy a repository from a remote server.
- git add: It is used to add files to the staging area.
- git commit: It will create a snapshot of the changes and save it to the git directory.
- git config: It can be used to set user-specific configuration values like email, username, file format, and so on.
- git status: It displays the list of changed files together with the files that are yet to be staged or committed.
- git push: It is used to send local commits to the master branch of the remote repository
- git checkout: It creates branches and helps you to navigate between them.
- git remote: lets you view all remote repositories. The following command will list all connections along with their URLs:
- git branch: It will list, create, or delete branches. For instance, if you want to list all the branches present in the repository
- git pull: It merges all the changes present in the remote repository to the local working directory.
- git merge: It is used to merge a branch into the active one.
- git diff: It lists down conflicts. In order to view conflicts against the base file, use
- tag: marks specific commits. Developers usually use it to mark release points like v1.0 and v2.0.
- git log: It is used to see the repository’s history by listing certain commit’s details. Running the command will get you an output that looks like this:
- commit 15f4b6c44b3c8344caasdac9e4be13246e21sadw
- Author: Alex Hunter <firstname.lastname@example.org>
- Date: Mon Oct 1 12:56:29 2016 -0600
- reset: This command will reset the index and the working directory to the last git commit’s state.
- git rm: It can be used to remove files from the index and the working directory.
- git stash: This command will temporarily save the changes that are not ready to be committed. That way, you can go back to that project later on.
- git show: It is a command used to view information about any git object.
- git fetch allows users to fetch all objects from the remote repository that don’t currently reside in the local working directory.
- git ls-tree: It allows you to view a tree object along with the name, the mode of each item, and the blob’s SHA-1 value.
- git cat-file: It is used to view the type and the size information of a repository object.
- git grep: lets users search through committed trees, working directory, and staging area for specific phrases and words
- gitk: shows the graphical interface for a local repository.
- git instaweb: It allows you to browse your local repository in the git-web interface.
- git gc: It will clean unnecessary files and optimize the local repository.
- git archive: It lets users create a zip or a tar file containing the constituents of a single repository tree
- git prune: It deletes objects that don’t have any incoming pointers.
- git fsck: It performs an integrity check of the git file system and identifies any corrupt objects.
- git rebase: It is used to apply certain changes from one branch to another.