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 a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

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

Adv 120x600

Looking for advertising?

Consider These Things If You Appreciate What stackorigin Does: Stackorigin is a community where you can ask questions and find answers, for free to everyone. We would appreciate it if you bought us a coffee if you liked what we were doing.

Buy me a Coffe

Adv 120x600

  • Random
  • Answers
    • On: June 28, 2021
    • Answer: 1

    How does the storage I get with Google One compare ...

    • On: August 9, 2021
    • Answer: 1

    What is the SMTP setting for Gmail?

    • On: December 9, 2021
    • Answers: 0

    How can I find the IUI treatment in Delhi-NCR

    • On: August 23, 2022
    • Answers: 0

    WHAT’S THE DIFFERENCE BETWEEN THE MIGRATE AND MAKEMIGRATIONS COMMAND IN ...

    • On: August 2, 2022
    • Answers: 0

    Purchase Clopress online no prescription USA, Buy clopress

  • strapcart_online
    strapcart_online added an answer Sildenafil citrate is a common ingredient in Cenforce 150mg tablets. This drug… March 21, 2023 at 11:42 am
  • strapcart_online
    strapcart_online added an answer Vilitra 20mg tablets are used to overcome the problem of… March 18, 2023 at 6:13 am
  • ashok
    ashok added an answer Not every girl, there are some girls out there who… March 16, 2023 at 4:15 am
  • strapcart_online
    strapcart_online added an answer Tadarise 40 Tablet is used to permanently remove the problem… March 4, 2023 at 5:48 am
  • strapcart_online
    strapcart_online added an answer Men use Cenforce D tablets for the treatment of sexual… March 1, 2023 at 5:59 am

Adv 120x600

Trending Categories

Health
2042Questions
, 4Followers
Programming
1236Questions
, 0Followers
Technology
216Questions
, 3Followers
General Knowledge
131Questions
, 0Followers
Business & Finance
84Questions
, 4Followers

Adv 120×600

Stats

  • Questions 4k
  • Answers 1k
  • Best Answers 105
  • Users 100

Users

niyadas823

niyadas823

  • 0 Questions
  • 0 Answers
nirala3

nirala3

  • 2 Questions
  • 0 Answers
Perrywalton

Perrywalton

  • 1 Question
  • 0 Answers
veeraa

veeraa

  • 0 Questions
  • 0 Answers
Stewesmitz

Stewesmitz

  • 0 Questions
  • 0 Answers

Adv 120×600

Explore

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

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.