fbpx

Top 30 GIT Commands With Setup and Advantages

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?

  1. Set up a username and email id in the main configuration file
  2. Initialize a Git repository. This setting will help the user in creating new projects or modify the existing one
  3. 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.
  4. Checking your file status that you have changed while working
  5. Make changes in your working directory
  6. You can save those changes that you don’t want to apply immediately
  7. Merge two branches
  8. Adding new remote repository

How Do You Set Up GIT Command-line Locally?

a. Download Git Commandline 

    i. (https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

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 your_email_address@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

  1. The basic flow of using Git is as follows:
  2. In the root directory or a sub-directory, create a new file.
  3. You can update the existing file as well.
  4. Add files to the staging area. This addition can be done by using the “git add” command and passing the necessary options.
  5. Commit files to the local repository using the “git commit -m <message>” power.
  6. Repeat.

Here are Some Important GIT Commands You Need to Know:

  1. git init: it creates a new local Git repository. 
  2. git clone: It is used to copy a repository from a remote server.
  3. git add:  It is used to add files to the staging area. 
  4. git commit: It will create a snapshot of the changes and save it to the git directory.
  5. git config: It can be used to set user-specific configuration values like email, username, file format, and so on. 
  6. git status: It displays the list of changed files together with the files that are yet to be staged or committed.
  7. git push: It is used to send local commits to the master branch of the remote repository
  8. git checkout: It creates branches and helps you to navigate between them. 
  9. git remote: lets you view all remote repositories. The following command will list all connections along with their URLs:
  10. git branch: It will list, create, or delete branches. For instance, if you want to list all the branches present in the repository
  11. git pull: It merges all the changes present in the remote repository to the local working directory.
  12. git merge: It is used to merge a branch into the active one. 
  13. git diff: It lists down conflicts. In order to view conflicts against the base file, use
  14. tag: marks specific commits. Developers usually use it to mark release points like v1.0 and v2.0.
  15. 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:
    1. commit 15f4b6c44b3c8344caasdac9e4be13246e21sadw
    2.  Author: Alex Hunter <alexh@gmail.com>
    3. Date: Mon Oct 1 12:56:29 2016 -0600
  16. reset: This command will reset the index and the working directory to the last git commit’s state.
  17. git rm: It can be used to remove files from the index and the working directory.
  18. 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.
  19. git show: It is a command used to view information about any git object.                       
  20. git fetch allows users to fetch all objects from the remote repository that don’t currently reside in the local working directory.
  21. 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. 
  22. git cat-file: It is used to view the type and the size information of a repository object. 
  23. git grep: lets users search through committed trees, working directory, and staging area for specific phrases and words
  24. gitk: shows the graphical interface for a local repository. 
  25. git instaweb: It allows you to browse your local repository in the git-web interface. 
  26. git gc: It will clean unnecessary files and optimize the local repository.
  27. git archive: It lets users create a zip or a tar file containing the constituents of a single repository tree
  28. git prune: It deletes objects that don’t have any incoming pointers.
  29. git fsck: It performs an integrity check of the git file system and identifies any corrupt objects.
  30. git rebase: It is used to apply certain changes from one branch to another. 


Leave a Reply