Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Git Tutorial
  • Git Exercises
  • Git Basic Commands
  • Git Cheat Sheet
  • Git Interview Questions
  • Git Bash
  • GitHub
  • Git Branch
  • Git Merge
  • Git WorkFlow
  • Git Hooks
  • Git LFS
  • Git Rebase
  • Git Cherry Pick
Open In App
Next Article:
Using Git on CommandLine
Next article icon

Using Git on CommandLine

Last Updated : 21 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Git is very important and powerful tool when it comes to the software development life cycle. Now in this article, we are going to see why git is used vastly in the software industry and what kinds of operations we can perform with git. So git is basically a distributed version control system for tracking changes in source code during software development. Git is designed for coordinating work among developers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. Git uses a version control system in which at some instances in a project a snapshot of the project is taken that is the progress made by that project is stored on a central repository. In simple words suppose the user is developing a web page first it will add its name and stored it as version then it added basic info and stored it as the second version then it added its profile picture and stored it as the third version now suppose the user added a wrong profile picture then there is always an option to revert back to the previous version after that it can add the correct profile picture.

Advantages of Version Control System

  1. Storing Versions: As explained in the above example If we encounter some error in our project code we always have the option to revert back to the previous version with the help of git it is easy to store version. If we try to store them manually It will be a hard task.
  2. Collaboration: In the software industry, multiple employees are working on the same project so with the help of version control system the main copy is stored on central remote server fetched by employees and after changes which are to be made are made employee uploads its own version to the central repository so others can fetch code updated by employees.
  3. Backup: In case if a central repository is crashed then anyone can push its local copy to the central server. As while making changes it has to be made on the local repository.
Git can be used with GUI as well as command-line. In this article, we are going to use the command line. GIT can be downloaded from here. After the successful installation of GIT, there is a need to configure git using the following commands:
  1. Open terminal:
    git --version
    To check version of git
  2. To set your username
    git config --global user.name "FIRST_NAME LAST_NAME"
  3. To set your email
    git config --global user.email "[email protected]"

Working with GIT commandline

Initializing a local repository:
git init
This command will initialise our local repository. git init Now our repository is initialized we can add some code to our project added files Checking status of the repository: As you can see a .git file is created as mentioned above. Now to check the status of these files, the following command is used:
git status
Here, working area is where files that are not added to repository yet are stored. These files are called as 'untracked files'. Staging area is files that are going to be a part of the next commit. Commit means basically storing a version of project at the current instance. As you add new files in your workspace you can add this files to staging area using git add command. git status Adding files to the repository: Now in the previous step we have seen that some files are untracked, with the help of git add filename we add these files to the staging area. git add command is used to add all files in the folder to the staging area
git add
git add After adding files to the staging area if git status is called again, then it will show files to be committed. git status Committing changes: Now files are ready to be committed they are ready to be added to the local repository
git commit -m "your message"
git commit command allows you to add your files to your local repository -m specifies that you have to pass commit message while committing a code git commit Every time a commit is made a SHA-256 key is created and assigned to that commit If we wanted to retrieve code at that commit it is possible using this id. Accessing log of commits: After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. That's where git log comes in picture. This command allows us to see all commits made by user. With the help of commit id you can refer back to the previous version.
git log
git log

Additional commands

git clone "Remote_repo_url"
With the help of git clone command, you can clone various repositories that are present on websites like GitHub, GitLab, bitbucket, etc. Any repository can be cloned as follows:
git clone "https://github.com/sanketpathak64/Kickstarter-Campaign.git"
Parallel development commands
git branch branch_name
This command allows to create a branch for the project. A branch is like exact copy of the project.
git checkout branch_name
This command allows to switch from one branch to another.
git merge branch_name
This command allows to merge a code of 2 branches in one branch.

Next Article
Using Git on CommandLine

S

sanketpathak64
Improve
Article Tags :
  • Git

Similar Reads

    How to Use Git Shell Commands?
    Git is a powerful version control system that is important for managing source code in modern software development. While there are many graphical user interfaces (GUIs) available for Git, mastering Git shell commands can significantly enhance your productivity and control over your repositories. Th
    3 min read
    How to run TestNG from command line?
    Running TestNG from the command line is a powerful technique for managing your automated tests efficiently. TestNG is a popular testing framework that provides various features for running and configuring tests. While IDE-based execution is common, using the command line offers greater flexibility a
    4 min read
    What is Switch Command-Line Interface?
    Network devices communicate with each other efficiently with the help of switches. For the management of network devices, we use different types of configuration methods to configure switches and manage their information flow, sharing, and resource allocation. The command line interface is one of th
    4 min read
    gs command in Linux with Examples
    gs command invokes Ghostscript, which is an interpreter of Adobe Systems PostScript and Portable Document Format(PDF) languages. After executing Ghostscript it reads further input from the standard input stream until it encounters 'quit' command. Syntax: gs [ options ] [ files ] ... Options: Below a
    2 min read
    Bash Script - How to use Command Line Arguments
    In this article, let us see about Command Line Arguments usage in Bash script. Arguments are inputs that are necessary to process the flow. Instead of getting input from a shell program or assigning it to the program, the arguments are passed in the execution part. Positional Parameters Command-line
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences