top of page

Basic commands to start working with git.

  • Writer: khyati sehgal
    khyati sehgal
  • May 28, 2018
  • 2 min read

In one of my previous blog, I have shared my experience why we need to use ‘Git’. In this post I will share basic commands to start with.

So lets get started.

To start with you need a machine where you want to use git. The choice would be Windows, iOs, Linux, etc. The links would be the same for the different operating systems, you just need to choose the one best fits your computer system.

For windows:

On your windows box download git , you can use these link:-

git-windows

Once installed, type git in the windows search/start up window and you will see two options:-

  1. Git GUI,

  2. Git Bash.

git

Git Bash – will give you Linux like environment where in you can work as an Linux operating system and perform git commands on bash.

Git GUI – window users who does not have linux box experience can use this to run git commands.

Other next thing you need to do is creation of account in github, or connecting with the git official repository. For this you need to simply sign up in https://github.com/. After this , you can directly push all your code directly from your local and can work on multiple branches/repository as and when required.

Creating a repo

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:khyati2010/.git
git push -u origin master
 

Create a new repository from github account by clicking on new repository:-

new-repo-git

Creating a new branch

git checkout -b   Switched to a new branch 'name-of-new-branch>'
 

Switching to existing branch

git checkout
 

Deleting an existing branch

git branch -r 
This will list all the existing branches of the current repo. git branch -d  
This will delete the branch from local 
git branch -D   
This will delete the branch from globally
 

Cloning a repository

Go to github in browser , select the URL of the repo you need to clone as shown below:-

cloning-a-repo

Cloning via command line

git clone
 
console-cloning

Initialising a repo

Go to the folder where you have clone/downloaded the code, and hit init command

git init
 
git-init

Checking the local changes

git status
 
local-changes
git-status-check-update

Adding local changes:-

One can add all the local changes by this command

git add .
 
git-add-all

Saving local changes:-

git stash 

Committing a code snippet:-

One can commit in two ways:- One with commit message as shown below

git commit -m "message" 
git-commit-with-message

and other without commit message

git commit 

Pushing the code to local and remote repository

git push origin 
before you create a new branch, make sure you do a
git fetch
that will pull the latest merge changes down for the develop branch
 
git-push-origin-master

Merging code to master from new branch

git fetch
git merge origin/master

Comments


bottom of page