What is Git? How to use Git commands?

Dhruva
2 min readSep 3, 2017

How the git works?

Disclaimer: I have written this documentation for my own understanding, use at your own risk

Git is a source control system which is associated with bitbucket where we input our credentials.

It is very easy to handle using command line.

One of the command line tool I like very much is the git bash which can be downloaded here https://git-for-windows.github.io/. This tool is very useful in creating new branches and we can see which branch we are working on.

Another GUI for tool for git is the source tree, where you can associate your git with, this can be downloaded from here https://www.sourcetreeapp.com/. You need to input your bitbucket credentials into the source tree after installing and can bring all the projects here, you can also find which branch you are working on in the source tree. Also this provides an easy GUI for staging and unstaging your files and pushing the files to the remote repository.

Another tool which can be associated when working in .net is the Visual studio which has good GUI for pushing the files into remote repository.

So, now we will see how git works with command line. There are around 10 major commands to work with while using git. Below are the commands

git clone <repo> — this will clone the entire repository into local

git checkout <branch name> — will checkout the branch already available

git checkout -b <branch name> — will create a new branch in your local

git checkout <filename> — will remove the changes to the file you do not want to commit

git reset HEAD <filename> — will unstage the file with changes

git rm — — cached <filename> — will unstage the newly added file

git add <file name> — will stage the files to point to current index and ready to commit

git add . — will add all the files to stage

git commit -m <commit message> — will commit the files with the commit message to remote repository

git push origin <your branch name> — will push all the changes to remote repository

Coming to bitbucket how it works in code reviews and merging code.

After committing the code to the remote repository, go to your branch and create a pull request and add reviewers to it, who will approve and merge the code to development branch.

Merging might create some conflicts if you are working on the branches. So inorder to resolve those conflicts in your local repository you need to follow below steps

First commit all your changes to your branch.

Now do a git pull origin <dev branch> from a development branch or other branch you want to work.

There you will find some merge conflicts.

Resolve them in your local repository

Test it and commit the modified files to the remote repository, with the resolved conflicts.

Then create a pull request

--

--