Git Basics

What is Git ?

  • The most widely used modern version control system in the world.
  • Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.

Steps to initialize a git project

  • Create account on Github and repo.  
  • Generate ssh key of your system and configure it in your Git hub account.
  • Create a new repository in your Github account.
  • Install git on your system.
  • Create a folder on your system.
  • Go inside the folder and execute command "git init" this must create .git directory in your folder.
  • Now copy and paste the remote address for ssh from your project on git hub account and execute the following command.
  • git remote add origin remote-url

How to know your remote url

git remote -v

Start tracking a file

git add <filename>

Start tracking all the files

git add .

commit code

git commit -m "your message"

Current status of directory

git status

Two ways to commit your tracked file

git commit -am "Your message"

 

or

 

git add file-name

 

git commit -m "Your message"

 

Logs

See logs in git

git log

Limit git log

git log -2

Details of commit

git commit --stat

One line log

git log --pretty=oneline

Graph View

git log --graph

Listing all branches

git branch

Create a new branch

git branch <branch-name>

Checkout to new branch

git checkout branch

Creating and moving to new branch 

git checkout -b <branch-name>

Cloning a git project

git clone <remote-url>

Pushing to remote

git push remote-alias branch name

Pushing everything

git push --all

Pulling everything

git pull

Pulling from a branch

git pull remote-alias branch name

Made with Slides.com