Basic Git commands

918

Basic Git commands: with example how to use git , given some very useful basic git git commandscommands given below .

 

  • git config
  • git clone
  • git add
  • git commit
  • git status
  • git branch
  • git merge
  • git pull
  • git push
  • git log
  • git diff

git config:


git config [options]

Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file use given config file
--blob blob-id read config from given blob object

Examples

git config --global user.name "User Name"
git config --global user.email "user Email"

git clone:


git clone /path/to/repository.git 

git add:

git add filename(add multiple file)
example:
git add sites/all/modules/custom/college/includes/my_college.inc

git commit:

[rizwan@dev-server docroot]$ git commit -m "college compare "
[my_brnch_name d3a219b] college compare
 1 file changed, 25 insertions(+), 39 deletions(-)

git status

[rizwan@dev-server docroot]$ git status
# On branch my_brnch_name
# Changes not staged for commit:
# (use "git add file..." to update what will be committed)
# (use "git checkout --..." to discard changes in working directory)
#
# modified: sites/all/modules/custom/college/includes/my_compare.inc
#
# Untracked files:
# (use "git add..." to include in what will be committed)
#
# ../.gitignore
# .htaccess
# nbproject/
# ../nbproject/
no changes added to commit (use "git add" and/or "git commit -a")

git branch

[rizwan@dev-server docroot]$ git branch
 about_us_update
 apply_college
 all_data
 new_data
* current_active_branch
 master
 last_2018_riz
 college
[rizwan@dev-server docroot]$ 

git merge:

Example :  Merge my_branch to  your_branch

Step – 1  

[rizwan@dev-server docroot]$ git checkout your_branch

 

Step – 2  

 [rizwan@dev-server docroot]$ git pull 

Step – 3


[rizwan@dev-server docroot]$ git merge my_branch

git pull 

 [rizwan@dev-server docroot]$ git pull 

git log 

[rizwan@dev-server docroot]$ git log
commit bec778e10c66c6455977289e13244d09a21f9bb0
Author: sahil <sahil@gmail.com>
Date: Tue Jan 2 19:39:48 2018 +0530

commit

commit 178fdf93cfa84ee2ad601d52343af307df1dbf12
Author: rizwan <rizwan@gmail.com>
Date: Tue Jan 2 16:45:25 2018 +0530

commit

commit b90648455aad295d92411505e14db8154a0e0f59
Author: irshad <irshad@gmail.com>
Date: Tue Jan 2 16:44:22 2018 +0530

commit

commit 5c7e3c460e22d9e09c9924b55dda92b3fa163a0e
Author: jamil <jamil@gmail.com>
Date: Tue Jan 2 16:42:12 2018 +0530

commit

commit 6760bb3495dfe134f6d0bd02fb152e5639f4c2ec
Merge: e1c42ef d1e22b1
Author: sahil <sahil@gmail.com>
Date: Tue Jan 2 15:58:47 2018 +0530

git diff 

[rizwan@dev-server docroot]$ git diff filename

git push

[rizwan@dev-server docroot]$ git push origin branch_name 

LEAVE A REPLY

Please enter your comment!
Please enter your name here