List of Some Basic git Commands

List of Some Basic git Commands

I am a part of many online php forums and I noticed that peoples around were asking many questions like

  • What is git?
  • What are git commands
  • How can we use git commands ?
  • Some basics git commands list
  • What is Git branching
  • Resolve Git Merging issues

So I decide to write a comprehensive article on some basic use of git and discus some basic git commands list. Most of the developers prefers to use the CLI for developing and testing due to the reasons of more security and no concurrency. So, if you love to work within in a team with no issue of concurrency, I will suggest to use the Git. We are going to learn about the basic git commands.

Basic Introduction of git

Git is the most popular platform among developers. It is an open source distributed version control system. It was designed for developers who love to work like a team. It handles everything from small to very large projects with speed and efficiency.

Git is easy to learn. It exceeds Supply chain management (SCM) tools like Subversion, Concurrent Versions System (CVS), Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

Setting up the git

I will share a simple guide for getting started with basic git commands. So, the installation method is very easy as like other software. Here are the download links for Windows and for Linux

1- Download git for Windows https://git-for-windows.github.io/

After downloading the git, install it. During installation, don’t change any setting. The defaults options/setting are pretty sensible for new users.

2- Download git for Linux: http://git-scm.com/book/en/Getting-Started-Installing-Git

Here, you will install the git packages by simply following the steps.

Configuring the git

Create an account and repository on Github. It is better to introduce yourselves to Git with your name and public email. So, you will configure your Git username and email using the following commands.

Importing a new project

Let’s suppose, you have a project and you want to work in it locally and then you will upload your updates in the live project. Firstly, go to the directory where you want to create your project as

Create directory for your project

Then

It will initialize empty Git repository in .git/. In other words, we can say that it will create a new local repository.

Clone Git Repository

You can clone working copy of repository from locally or remotely  by running below commands.

For locally run below command

For Remote run below command

There is another solution if you don’t like to run above commands that is after  adding  the remote path that will connect your current repository to remote repository  simply run the git pull command and it will pull the remote repository on your locally configured repository.

Adding Remote Path

Updating Remote Path

Here, the projectName is the name of github repository. To see the list use

Now, you will need to pull (download) that repository into your previously created folder. Use

After pulling, start working on the repository files. When you are done with the updates. Use these commands to push (upload/update)  your changes into repository. If you have created a new file/folder or renamed a file/folder, you first will run the add command as

For single file

For multiple files

For multiple files and directories

Then you will run the commit command prior to push.

Commit changes to head but not yet to the remote repository

Commit all files you have added new files and update the files.

Now make changes on your remotely master branch.

View the list of files you hav updated and those that are still need to add or commit.

Recover a deleted file (notice apply the space before and after the dash)

Temporarily discard local changes

Re-apply stashed away changes

So far, we have covered the basic git commands. These basic commands will help you for setting up your github repository to your local system. I hope you will find it helpful.

Advanced git commands list