How To Use Git ? (Beginner)

Image from — Google search

What is Git?

Is Git & Github are same?

Let’s get started on learning how to use git step-by-step.

Download Git

git --version

Create a Local repository

git init

Add some files

Staging

git add <file name>
Ex:
git add helloworld.java
//In case if you have to add multiple files
git add <file name> <file name> <file name>
Ex:
git add helloworld.java Employee.java Customer.java
// In case if you want to add all the files and folders inside your project folder
git add .

Committing

git commit -m <commit message>
ex:
git commit -m "Initial Commit"
git commit -a -m <commit message>
Ex:
git commit -a -m "file is modified"

Status

git status

Log

git log

Branches

Branches — Picture by-google

Create a new branch

git branch <branch name>
Ex:
git branch test

Switch to another branch

git checkout <branch name>
Ex:
git checkout test

Merging

git checkout master
git merge test
Merge — image by-google

The Remote Git Repository

Remote Repository URL
git remote add origin <Remote repository url>
Ex:
git remote add origin https://github.com/Mohamed-Arshad/Krish-LP-Training

Push

git push -u origin <Local Branch>
Ex:
git push -u origin master
//If you want to push all of your local repository's branches to a remote repository
git push -all

Pull

git pull origin <remote branch>
Ex:
git pull origin master

Clone

git clone <Remote Repositary URL>
ex:
git clone https://github.com/Mohamed-Arshad/Krish-LP-Training

More on Git

Tags

Stash

Keep Learning ❤️

Associate Software Engineer at Virtusa