Git Commands

Kamal Walia
KodeMadeEasy
Published in
4 min readFeb 3, 2019

Assuming that you now have a hold on the basics of GIT let’s dive into basic GIT Commands.

First, you need to install Git on your computer. Follow these instructions if you haven’t done that already. Once you have Git installed, we can move on to basic Git commands.

  1. Configuring Git: Now that you have Git on your system, you’ll want to do a few things to customize your Git environment. To tell Git who you are, run the following two commands:
$ git config --global user.name “<Your Name>” 
$ git config --global user.email “<Your Email>”

For Ex:

Configuring Git
Confirm that you have set the Git name and email successfully

2. Your Editor: Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses your system’s default editor.

$ git config --global core.editor emacs$git config --global core.editor "code --wait"
// --wait flag is to instruct the git bash to wait until you finish writing to the file.

For Ex: I’m using visual studio code as my default editor to set it as default editor in your git bash:

Setting visual studio code as the default editor

3. Creating a new repository: git init command is used to create an empty git repository. Assuming you’ve already created an empty directory for your project.

$ git init

For Ex:

Creating an empty repository

4. Check the status of your repository: git status lists all new or modified files to be committed.

For Ex:

Status of repository

5. Cloning a repository into your local machine: git clone [url] this will download the project and its entire version history.

For Ex:

git clone https://github.com/Kamal-Walia/CookieEater.git

6. Staging your files: Before you are ready to commit changes to your newly created repository you need to understand about “git add” which we will use to add our files to the staging area.

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. Its technical name in Git parlance is the “index”, but the phrase “staging area” works just as well.

$ git add <file-name-1> <file-name-2> <file-name-3>
// use ".", "*", "-A" to add all files to the staging area without //double qoutes.

6. Committing a directory: Record changes to the repository.

$ git commit -m "message"

Every commit in git is associated with a commit message which can be anything in general but here you basically write a statement that reflects what changes you’ve done in the repository.

7.Branch: A branch in Git is simply a lightweight movable pointer to one of your commits. The default branch name in Git is master.

$ git branch
// Lists all local branches in the current repository
$ git branch [branch-name]
// Creates a new branch

8.Git Checkout: To switch to an existing branch, you run the git checkout command.

$ git checkout [branch-name]

9. Git Push: To upload changes that you’ve made to your git repository to a git client, for example, GitHub use git push

// Before you are ready to push changes to the server be sure to:1)Either specify the URL from the command-line or configure a remote repository using:                                                
$git remote add <name> <url>
//and then push using the remote name
$git push [alias] [branch]

10. Git Pull: This will download the git repository with it's history and incorporates changes to your local repository.

$ git pull <remote> <branch>

That’s it for basics to Git Commands. To learn more commands you can always reference the official git website:-https://git-scm.com/docs

--

--

Kamal Walia
KodeMadeEasy

👨‍💻 Software Engineer | Tech Enthusiast | Wordsmith 📝