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 of Windows, iOs, Linux, etc. The links would be same for different operating system, you just need to choose the one best fits your computer system.
On your windows box download git , you can use these link:-
Once installed, type git in the windows search/start up window and you will see two options:-
- Git GUI,
- Git Bash.
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 firstname.lastname@example.org:khyati2010/.git git push -u origin master
Create a new repository from github account by clicking on new repository:-
Creating a new branch
git checkout -b <name-of-new-branch> Switched to a new branch 'name-of-new-branch>'
Switching to existing branch
git checkout <name-of-new-branch>
Deleting an existing branch
git branch -r This will list all the existing branches of the current repo. git branch -d <name-of-new-branch> This will delete the branch from local git branch -D <name-of-new-branch> 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 via command line
git clone <path-of-repo>
Initialising a repo
Checking the local changes
Adding local changes:-
git add .
Saving local changes:-
Committing a code snippet:-
One can commit in two ways:- One with commit message as shown below
git commit -m "message"
and other without commit message
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
Merging code to master from new branch
git fetch git merge origin/master