Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 1.87 KB

3. Git Basics.md

File metadata and controls

70 lines (52 loc) · 1.87 KB

Git Basics

What is a Repository (repo)?

A git "repo" is a workspace which tracks and manages files and directories with in a git initialized project.

Basic Git Commands

  1. To initialize a git within a project
git init
  • It is used to initialize a git setup within a project to track changes.
  • This is the first basic git command required to start git.
  • Can be used only once in a project at the begining.

Note: about .git directory

  • After executing git init, you'll probably notice there is one .git named hidden directory get automatically created by git.
  • This directory holds all the history of your project after installation.
  • It is made hidden because you can't delete that accidentally.
  • If deleted manually then all the history will be deleted.Then you need to do git init again.

Warning: DO NOT INITIALIZE A REPO INSIDE A REPO

  • Before initializing a repository must check whether that repo is already initialized or not.
  • you can use git status command to verify whether you're in git repo or not.
  1. To check status
    git status
    
  • It is used to check status of changes made in git repo
  • Either the changes will be untracked or tracked if added to staging area.
  1. To add file to staging area
    git add file1.txt
    
    or to add everything use the given commands below
    git add -A
    git add .
    
  • It is used to add files to staging area.
  • staging area means where files are ready to be commited.
  1. To commit the changes
    git commit -m "commit message"
    
  • It is used to commit the staged changes.
  • commit message should represent the commit changes
  1. To log the previous commits
    git log
    
    or to log commit messages in one line
    git log --oneline
    
  • It is used to see previous commits made
  • one line argument is really helpful to display log messages in one line