Saturday, September 21, 2013

How to make a directory as git repository


Many a times we have  non directory and we want to make them as git repository.In such a situation open git bash and follow following steps
git init

git add .

git commit -m 'message'

git remote add origin <url of remote repository>

git push -u origin master

Working with Git

Step 1. Clone your repository to your local system
first create a new directory which you want to be as repository
Open Git Bash move to the directory by using  cd path/to/my/repo
Now clone the repository using

$ git clone https://url of your remote repository/newuserme/repository.git
you will get a message like this
Cloning into 'repository'...
Password
warning: You appear to have cloned an empty repository.

Step 2. Explore your repository and fix a problem

$ ls -al 
This will give the list of files in repository.

Step 3. Create a README, add it locally, and push it to the remote server

create readme file  with content about file and save it in local folder .This file is a text file.
Now check the status of file on Git Bash

$ git status 

Now add the Readme file using 

$ git add README

commit the changes using following command

$ git commit -m "Here should always be some meaning full message".

Now we can push the changes to the remote server using following command

$ git push -u origin master

It will ask for you for password.
Password: 
Note:

Sometimes while commiting you we get an error like 
*** Please tell me who you are.

Run

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

to set your account's default identity.

Omit --global to set the identity only in this repository.

In such a situation enter these two commands

 git config --global user.email "here you should put your email address"

  git config --global user.name "Your Name"


Now if someone else working on same code has updated the code then we can get the updated code using git Pull command

$ git pull origin master