Day 1 - Introduction to Git and Github

Installing Git

You can easily download Git on your system by opening this link
%[git-scm.com/download/win] but if you are a linux or mac user you can open the link %[git-scm.com/book/en/v2/Getting-Started-Inst.. and learn how to install Git on your system.

Git Bash

Git Bash is the terminal for executing git commands. Bash is an acronym for Bourne Again Shell. A shell is a terminal application used to interface with an operating system through written commands.

Setting up Git

Introduce yourself with git. Let it know what to call you and add your email using these commands in the terminal :

  • git config --global user.name 'Your-name'
  • git config --global user.email 'Your-email'

Two Ways to initialize Git

  1. Initialize a repository
  2. Clone an existing repository

Go to folder from File explorer; right click to open Git Bash here. Then to initialize a repository use this command in the Git Bash terminnal:
git init or if you use VS Code as your text editor you can press(CTRL + `) to open terminal and you can write all your git commands in VS Code's terminal to commit and push your code to your repository.

Git life-cycle.png

Stages of files

  • Untracked Files
    Git has nothing to do with these files. This is the default stage of files.

  • Un-Modified Files
    Once the file is pushed, its first version will be unmodified until we modify it. Whenever you check the status of git it will show you the stage of all the files whether it is modified, unmodified or else.

  • Modified Files
    Once the file is changed even a single word is changed, then it will be considered as modified and git will show it to you. and this file is now again ready to be staged.

  • Staged Files
    From untracked when the user adds these files to the git's working tree, it is added to the stage from where the files are ready to commit and then pushed on the remote server.

Git Status Commad

You will be using this command many times. This command shows the status or stage of files in directory.
Which files are getting tracked?
Which are untracked?
Which are modified?
Which are staged and which aren't?
and much more...

  • git status

Adding files to stage

you can stage all the files by using :

  • git add -A

or you can add only one file to stage by using:

  • git add filename

To commit i.e. Save

To start tracking in your project, you first need to make an initial commit by using command:

  • git commit -m "Your Message Here"

Remove File

If you want to remove file from the staging area but not from the working area then use this command:

  • git rm

Branches

Master is the main branch in git. Here you have a working tree and branches. If you want to make changes to some files and you don't want to create to waste your time to create a copy of project and make changes, Branches can help you a lot. You can easily create your own branch in which you can make changes which will not be reflected towards the master.

Create new Branch

  • git branch branch-name

To view all branches of project

This shows the current branch in green color

  • git branch

To jump to any branch

  • git checkout branch-name

To merge 2 branches

  • git merge new-branch

Clone a project

  • git clone url folder-name