Many of you know about git or git commands. If you don’t know about git toady in this article I will explain to you what is git and some basic commands that everyone should know.
Here are the few basic questions regarding git.

  • 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

Most of the developers prefer to use the CLI for developing and testing due to the reasons for more security and no concurrency. So, if you love to work within in a team with no issue of concurrency, I will suggest using the Git. We are going to learn about the basic git commands.

Basic Introduction of git

Few Basic git Commands that You Should Know!

Git is the most popular platform among developers. Git is an open-source distributed version control system. It was designed for developers who love to work as 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/settings 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.

$ git config --global user.name "Geeksteps"
$ git config --global user.email "[email protected]"

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

$ cd d:\projects\folder

Create a directory for your project

$ mkdir project-name

Then

$ git init

It will initialize an 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 a working copy of the repository from locally or remotely by running the below commands.

For locally run below command

$ git clone /pathtToRepository
$ git clone /pathtToRepository

For Remote run below command

$ git clone [email protected]:/PathTorRepository
$ git clone [email protected]:/PathTorRepository

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

$ git remote add origin https://github.com/username/{projectName}.git

Updating Remote Path

$ git remote set-url origin https://github.com/username/{projectName}.git

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

$ git pull origin master

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 the repository. If you have created a new file/folder or renamed a file/folder, you first will run the add command as

Single file

$ git add {YourNewFileName}

Multiple files

$ git add *

For multiple files and directories

$ git add –A

Then you will run the commit command prior to push. Commit changes to head but not yet to the remote repository.

$ git commit -m "My commit message"

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

$ git commit -a -m "My commit message"

Now make changes on your remotely master branch.

$ git push origin master

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

$ git status

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

$ git checkout - filename

Temporarily discard local changes

$ git stash

Re-apply stashed away changes

$ git stash apply

Final Words

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. Do visit my website for awesome articles like this.
Happy Coding ❤💕

LEAVE A REPLY

Please enter your comment!
Please enter your name here