Some Basic Git Commands which you need to know if you are using Git.

krishankant singhal
3 min readFeb 12, 2019

--

Git is a distributed version control system. When we say distributed version control means everyone have fully repositories on their system instead of only working directly. In case of SVN on our local system we have working directory and require network connection to remote repository to get history and other info. But in case of Git we get whole repo with history , branches and working copy.

Distributed Version Control

To Download the code from Git, We use git clone command.

git clone <url of repo which you want to download>

when we run git clone, It clone the remote repository in your local and you get exact replica of repository on your system. By default it point to default branch, which generally is master. we can get to specific branch during clone itself, syntax of it is.

git clone --branch <branchname> url

Here it will download all branches but will switch to branch specified once source is cloned.

if we clone repo using --single-branch option, it Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.

git add . or <filepath>  // . refer to current directory so all untracked or modified file will be added to staging area.

git add command is used to tell git that i have changed these files, please use these files in next commit. so when you make any changes to file. if it is existing file , git marked it as modified file, new file as untracked , but it stay in your working directory. but when you run git add command it is moved to staging area(index area).

git status

git status is used to check the status of your staging and working directory state. it shows list of file which has been changed or created and their current state in git . As Well tell us which files are in staging area and which are in working directory.

git commit -m "commit message"

git commit will commit the files in staging area into your local repository. here -m is for commit message.

git pull or git pull orgin <branchname>

git pull is used to fetch the changes from remote (commits, remote branches , tags) etc from the remote repository and merge commits from current remote tracked branch to your current branch if we are using blank git pull. if you are using git pull with origin branchname, then will bring all changes but will merge passed branch to your current branch.

git push or git push origin <branchname>

git push is used to push the commits which are in your local repo but not present in remote repo.

git log

git log command to check the history. by default it list the commits history of your current branch.

There are plenties of command and options which git provide , Which is difficult to mention in one post. But above mention command is must if we are using git.

--

--

krishankant singhal
krishankant singhal

Written by krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.

No responses yet