Tuesday 27 August 2013

Git Basics

Today I am going to share some of the basic commands of the git.
Starting with a brief description about git :

In software development, Git is a distributed version control and source code management system with an emphasis on speed. Read More
Source:wikipedia

Now coming to commands,I am not going to explain each and every command in detail as the git documentation is enough for that. Will only give brief introduction about them

1) Create your account in github

Goto https://github.com and create your account.

2) Create a repository

Create an empty repository where you want to push the data from your local machine.

Give a name to the repository
A url will be generated for your respository. This is useful in the later process while adding a remote in your local for pushing and pulling purpose. 



3) git init

This command creates an empty git repository.
Suppose you have a folder named "GitTest" in your local. Now you want to push this folder to github then go inside that folder using command line and type "git init".

3) Now add the git remote you created in github.com in your local so that the local changes are pushed to that url .

 git remote add <short name for the url> <url>
 eg : - git remote add origin https://github.com/nikitasingh/GitTest.git

Here origin is the short name for the url

git remote -v will list all the remotes which are added for your repository.

5) Now create some file like "xyz.txt" inside that folder. (Suppose this is the file you want to push to the github)

6) git add

To add the newly created file type-

git add xyz.txt

To add all the files in your folder to github type:-

git add .

7) git commit

File you just added is not ready to be pushed yet, If you will run the git push command without running commit command this file will not be added to your github repository.

so to commit this file type-

git commit -m "first file added" xyz.txt

Here -m is used to give commit messages, you cant run commit command without giving a commit message

8) git push

The next step is to push the changes to the github repository from your local machine. To do that type:

git push origin master

It will ask your login credentials to push the changes.

9) git pull

git pull is used to fetch the changes from the github repository to your local machine.
When two or more people are working on the same repository, it is must to pull the changes so that you have the updated project in your local.

9) git status

If you will type git status it will show the files with following details:-

  •  unmodified files
  •  modified files
  •  added files
  • deleted files
  • renamed files
  • copied files
  • untracked files

No comments:

Post a Comment