Basic commands to start working with git.

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:-

https://git-scm.com/download/win

https://git-scm.com/downloads

git-windows

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

  • Git GUI,
  • 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

Author: Khyati Sehgal

Khyati has more than 12 years of experience in quality assurance engineering. Khyati has worked extensively on Manual and Automation testing of various technologies and domains like data quality. From last 6 years, She is leading QA Activities on Agile/Scrum projects while continuously contributing in playing role as a Scrum master, continuous integration, iteration planning, facilitating requirement analysis and closure. On automation front, She has explored gui, web services and mobile automation. Tools/ Technologies used:- Selenium/WebDriver, Core Java, JUnit, TestNG, Maven, SoapUI. Jenkins, Appium, Selenium backed and selenium remote driver. Have delve into android phone/tab of verison upto 6 (marshmallow), ios phone/i pad, and mobile websites

2 thoughts on “Basic commands to start working with git.”

  1. Hi! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My website looks weird when browsing from my iphone 4. I’m trying to find a template or plugin that might be able to fix this problem. If you have any recommendations, please share. Appreciate it!

    Like

Leave a comment