Linux Basics Linux Commands

Useful GIT Commands

git commands
useful git commands

Useful Git Commands

This post gives some useful Git Commands which will help you to play with a git repository.

What is Git?

Git is a program that helps to do version control. It is able to keep track of files. To keep track of file changes, GIT uses content snapshots, checksums and metadata. This is how Git providing version control. Git created by Linus Torvalds the one who created the Linux kernel.

Check below for some useful Git Commands:

How to clone a Branch:
git clone <url>
To create a branch:
git checkout -b <branch_name>
To show all branches:
git branch
How to add a change in the working directory:
git add <file>
To move to the master branch:
git checkout master
To pull updates: (Only Run from Master branch)
git pull
To move to the newly added branch:
git checkout <branch_name>
To get the difference:
git diff <file>
To get the status:
git status
To save the changes:
git commit <file_name> -m "comment"

A commit in GIT is a state, actually the current state of files and the current commit is known as HEAD. Also, we can move the HEAD using different commands.

To commit all changes:
git commit -am "comment"
To push the changes:
git push origin <branch_name>

It will give a URL. Give that for merging.

To get the whole log:
git log
To pull all files other than the changed ones:

This needs to be done inside the branch

git rebase master
Then, Push Your Changes:
git push -f
To delete a branch:
git branch -d <branch_name>
To delete a branch forcefully:
git branch -D <branch_name>

That’s it!

Also Read:

If you like the post Understanding top Command and wish to receive more articles from us, please like our FB page: GrepItOut

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments. For more details on our services, please drop us an E-mail at info@grepitout.com

Topics