Important git commands with description

  1. Configuring Git

setting global user name and email, these are identification who is working with the project(repository)

$ git config –global user.name “My Name”

$ git config –global user.email myEmail@example.com

  1. Creating a new repository –git init command

initializing git local repository in your computer:

$  git init

  1. Checking the status –git status

$ git status

  1. Adding to Staging area –git add

suppose hello.txt is our file and we have made some changes in it. Now, we need to add in staging area before committing :

adding a specific file

$ git add <file-name>

Example:

$ git add hello.txt

adding all files:

$ git add –A     or

$ git add  .

  1. Committinggit commit command

git commit -m  “<message>”

Example:

$ git commit -m “Initial commit.”

Work with remote repository: 

  1. Connecting to a remote repository –git remote add command

$ git remote add origin<remote repository url>

Example:

$ git remote add originhttps://github.com/Md-MamunAbdulKayum/practice.git

2.  Cloning a repository –git clone command

getting remote repository to local

$ git clone https://github.com/Md-MamunAbdulKayum/practice.git

    3.  Upload local change  to a server –git push command

git push origin <branch-name>

Example:

$ git push origin master

    4. Get changes from a server to local –git pull command

$ git pull 

or

git pull origin <branch-name>

Example:

$ git pull origin master

Working with Branch: 

  1. Creating new branch – git branch command

git branch <branch_name>

Example:

$ git branchdev

  1. Switching to  a branch –git checkout command

$ git checkout <branch-name>

Example:

$ git checkout dev

  1. Merging branches –git merge<branch_name>

Suppose I in master branch, marge with dev  branch

$git merge dev