Git & Github

Git & Github


||||||||||||||||||||||||||||||||||||||||||||||||||


Installation

  • Install Git

    Verify Installation

    Don’t know if git installed successfully or not?

    • Verify if Git is installed, by using the following command in the Git Bash Terminal :
      git --version
      
      This Command will return the version of git in floating digits which verifies that Git has been installed successfully


Get started with Git

Don’t know where to start?, Check this easy stepwise guide below:

1. Create a New Folder

mkdir Folder

This command will create a new folder named Folder in your Current Directory(cd)

2. Initialise Git

cd Folder/
git init

This command will create a new hidden folder inside your Folder

3. Create Readme.md file

cat > Readme.md

This command will create a new Markdown file namely Readme.md inside Folder

Hello World!

Type above text or any other Markdown Text inside Readme.md file

press ctrl+c

Press Ctrl+c to save & exit the Readme.md file

4. Staging

git add .

Use this command for staging all the files

Or

git add Readme.md

Use the following command for staging the Readme.md file

5. Committing

git commit -m "My First Commit"

Use this command to commit the Readme.md file with the message as "My First Commit". Use relevant messages while committing

6. Remote Repository

Here we will be using GitHub for the remote repository

  • Go to Github
  • Create a new Repository by clicking on either of these 2 buttons shown below: image.png
  • After this it will redirect to a new Repository form, Fill the Name of the repository you want to give to your very first Repository (e.g. Understanding-git)
  • Once the Repository is created, you will be able to see a page somewhat similar to the following screenshot : image.png
  • In this Screenshot, the highlighted Green Line is the Repository URL
  • Copy the Repository URL and add in the below command to add the remote to origin
    git remote add origin [Repository URL]
    

    7. Git Push

    git push -u origin master
    

    This Command will push all the code from the local repository into the remote repository


Additional Commands:

Some more commands to help you manage with your version control journey:

Git Pull

git pull origin master

This command will pull the latest changes from the remote repository into the local repository. The remote repository code is updated continuously by various developers, hence git pull is necessary

Git Clone

git clone [repository url]

This command is used to clone an existing remote repository into your computer

Git Status

git status

This command find out information regarding what files are modified and what files are there in the staging area

Git Log

git log

This command will print out all the commits which have been done up until now

New Branch

git branch [Branch Name]

This command creates the Branch named as [Branch Name]

Git Checkout

git checkout [Branch Name]

This command will switch(checkout) current branch to [Branch Name]


||||||||||||||||||||||||||||||||||||||||||||||||||


image.png

                       CONGRATULATIONS 
                          ¯\_(ツ)_/¯
         Now you know the basics of how to use Git.