Git Commands

GIT is the most popular tool among for most of the Source Code Management Systems like Bit Bucket and GITHUB. GIT Bash commands are most frequent in used and required when we work on any Software Development projects. In this blog we covered most popular GIT CLI commands which everyone should know. In this tutorial, each command is explained with examples and snapshot:

1. git init

git init is the first command if you want to add your project in version control system. This command is used to initialize git repository.

git init

 

2. git config –global user.name

This command is used to get details of git username.

git config --global user.name

3. git config –global user.email

If you want to check user email id which is used during set up then you need to run command

git config –global user.email

git config –global user.email

4. git clone

Git Clone command is used to download existing repository on your machine. Refer below example

git clone https://github.com/ajeetyadawa/Java-For-AutomationTesters.git

git clone

5. git status

If you are working on any development project and want to check modified/deleted or changed files then you need to run “git status” this command will gives all the modified files.

Git Status – list of modified files

$ git status

git status

 

git status

6. git add filename.extension
        git add .

git add command used to add file in git repository. If you want to add specific file then you need to pass git add filename.extension or if you want to add all files then you need to add git add .

Command to add all files

 git add .

Command to add specific files

Command to add specific files

 

7. git commit –m ‘TASKID- Updated Code’

Once after adding files in git repository we need to commit files in local repository for that we need to run git commit –m ‘followed by message’ .

$git commit –m ‘followed by commit messages’

git commit –m ‘TASKID- Updated Code’

8. git push

git push should be used for moving local commit on git remote.

$git push

git push

 

9. git log

This command is used to check commit history in current branch. Using this command we can get previous commit id, commit messages and timestamp.

$git log

git log

10. git branch

Git branch is used to create, list and delete branches from local repository.

Git branch  -d branchname   – This command can be used to delete gitbranch.

git branch11. git branch new-branchname

This command can be used to create new- branch

git branch new-branchname12. git checkout

GIT checkout command is used to switch from one branch to another branch.

$git checkout master — > This command can  be used to switch into master.

Command to create new branch and switch into it:

13. git reset –hard

14. git pull

Git pull – command is requires to fetch the remote repository changes and merge into current project

15. git rm filename

This command is used to delete file from git repository.

$ git rm filename -f

 

Hope above tutorials helps you to understand about git commands and guide you whenever needed. Feel free to Contact Us to us on info@thoughtcoders.com  or call us on +919555902032.

Write A Comment