GIT basic commands

Git is awesome, at least I think it is. The moment I got familiar with Git, I fell in love with it. Git has a huge list of different commands to make your development work efficient and more productive. In this post I will list out the basic commands which I am sure the developers use in there day to day life.

To initiate or create a repository:

git init

To add all the files in a repository:

git add -A

or

git add --all

If you want to stage new and modified files, without staging the deleted ones:

git add .

If you want to add modified and deleted files but not the new ones:

git add -u

The default branch in git is master. Branching is the key element in git, and in my opinion, it is what makes git cool.

To create a simple branch out of master branch:

git checkout -branch new-branch-name master

The above command is same as,

git branch new-branch-name
git checkout new-branch-name

You can see difference between two branches by using the command:

git diff your-branch-name

And you can merge the changes from another branch using the command:

git merge your-branch-name

The above mentioned command will merge changes to your current branch with the changes coming from your-branch-name.

If in case you want to pick specific commits, then issue the command:

git cherry-pick <commit-id>

To commit or stage the changes, you can execute this command:

git commit -am "your commit message"

In the above command, -a tells the git to include modified and deleted file changes and -m is for the message.

You can also look up the changes in the local repository using the command:

git status

 

I have written other posts for git branching operations and deleting operations.