Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

Stackorigin – The Community of Question and Answers

Stackorigin – The Community of Question and Answers Logo Stackorigin – The Community of Question and Answers Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
Home/Basic Git Commands

Basic Git Commands

What is Git

Git is a free, open-source and version control system. By using Git you can see what changes have been made to the project code.

What is a GIT Repository

Git repository is the .git/ folder inside a project. This repository tracks all changes made to files in your project, building a history over time. Meaning, if you delete the .git/ folder, then you delete your project’s history.

There are two repository:

  1. local repository
  2. remote repository

Git Workflow

local repository has three different stages. Those are:

  • Working directory
  • staging area
  • Local Repo

working directory is where new files are created, old files are deleted, or where changes are made to already existing file

Once changes are made, they are added to the staging area.

Once the changes are complete​, the staging area will contain one or more files that need to be committed. Creating a commit will cause Git to take the new code from the staging area and make the commit to the main repository​. This commit is then moved to the Local Repo.

Getting started with Git:

  • git init is one way to start a new project with Git
git init
  • git add is a command used to add files that is in the working directory to the staging area.
git add -A  # stages all changes.
git add .    # stages new files and modifications, without deletions (on the current directory and its subdirectories).
git add -u  # stages modifications and deletions, without new files
  • git commit is a command used to add all files that are staged to the local repository.
git commit -m "add a commit message here"
  • git push is a command used to upload/push local repository content to a remote repository. In the remote repository, all files and changes will be visible to anyone.
git push remote_url branch_name
git push remote_url branch_name -force   #git force push allows you to push local repository to remote without dealing with conflicts
  • git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.
git fetch repository Url
git fetch branch_URL branch _name #To fetch a specific branch
  • git merge is a command used to get the files from the local repository into the working directory.
  • git pull is a command is used to fetch and download content from a remote repository to local repository. It is equivalent to a git fetch and a git merge .
git pull remote branch URL
git pull remote/branchname  (Recommended)
  • git status is a command lets you see which changes have been staged
git status
  • Git log is a utility tool to review and read a history of everything that happens to a repository.
git log
  • git –version is a command used to check git version
git --version
  • Configure your Git username and email address.
git config --global user.name "YOUR_USERNAME"
git config --global user.email "yourmail@gmail.com"

git config --global --list   # To check the info you just provided

Share
  • Facebook

Sidebar

Ask A Question

Stats

  • Questions 1k
  • Answers 1k
  • Best Answers 80
  • Users 81

Adv 250x250

Adv 234x60

  • Recent
  • Answers
  • ashok

    How do I get the current time?

    • 2 Answers
  • ashok

    How to Install and Use Git on Windows

    • 1 Answer
  • ashok

    How to Check Git Version

    • 2 Answers
  • arjun

    Which institute is best for a data science course in ...

    • 1 Answer
  • ashok

    git stash and git pull

    • 1 Answer
  • pratap
    pratap added an answer How do I get the current time in Python: The time module… June 29, 2022 at 9:08 am
  • pratap
    pratap added an answer How do I get the current time in Python: Use datetime:… June 29, 2022 at 9:04 am
  • hari
    hari added an answer How to Install and Use Git on Windows Git is… June 29, 2022 at 8:24 am
  • sam
    sam added an answer How to Check Git Version: $ git --version git version… June 29, 2022 at 8:13 am
  • sam
    sam added an answer How to Check Git Version: In a command prompt: $… June 29, 2022 at 8:13 am

New Members

Sakshigupta1998

Sakshigupta1998

  • 0 Questions
  • 0 Answers
legal heir certificate online apply

legal heir certificate online apply

  • 0 Questions
  • 0 Answers
Mutual divorce process india

Mutual divorce process india

  • 0 Questions
  • 0 Answers
propertyregistration

propertyregistration

  • 0 Questions
  • 0 Answers
Best Gynecologist Hospital in Delhi

Best Gynecologist Hospital in Delhi

  • 0 Questions
  • 0 Answers

Adv 234x60

Trending Categories

Programming
825Questions
, 0Followers
Technology
209Questions
, 3Followers
General Knowledge
127Questions
, 0Followers
Business & Finance
81Questions
, 4Followers
Employment
73Questions
, 3Followers

Trending Tags

django (95) git (57) google (29) india (35) mysql (22) oil (54) pandas (23) python (241) usa (25) youtube (24)

Recent posts

    • On: June 29, 2022

    Bitbucket Cloud recently stopped supporting account passwords for Git authentication

    • On: June 21, 2022

    Best Telegram Movie Channels

    • On: June 17, 2022

    How to Open ICICI Bank Savings Account

    • On: June 15, 2022

    How to Download Your Own Twitch Videos

    • On: June 14, 2022

    How To Permanently Delete Your PSN Account

Explore Our Blog

Adv 234x60

Subscribe

Explore

  • Recent Questions
  • Most Answered
  • Answers
  • No Answers
  • Most Visited
  • Most Voted
  • Random

Footer

Stackorigin - The Community of Question and Answers

Stackorigin

Stackorigin is the world’s largest Q&A networking site, Stackorigin community brings you the collaboration of all the various Questions and the related Answers given by the community.

About

  • About Us
  • Contact Us
  • FAQ
  • Submit Guest Post Article on Technology, Education, Health, Apps, Gadgets, IoT, AI, Business, Digital Marketing and More

Info

  • Privacy Policy
  • Terms and Conditions
  • Community Guidelines
  • Tags

Products

  • Tutorials
  • Advertising
  • Categories
  • Corona
  • StackHow

Follow

© 2022 Stackorigin. All Rights Reserved.