Sunday 25 November 2012

GIT REPOSITORY





A Git project using two main approaches. The first takes an existing project or directory and imports it into Git. The second clones an existing Git repository from another server.

Initialize a git repository in a directory


Go to the project’s directory and type
$ git init 
This creates a new subdirectory named .git that contains all of your necessary repository files. If you want to begin version-controlling existing files, then you need to start tracking files and do a initial commit. git add commands specify the files you want to track.git commit commands used to commit.
$ git add *.c
$ git add README
$ git commit -m 'initial project version'
Cloning a repository

If you want to get a copy of an existing Git repository, use git clone command.
git clone [url]if you want to clone the Ruby Git library called Grit
$ git clone git://github.com/schacon/grit.git 
if you want to clone the Ruby Git library called Grit in a new directory new
$ git clone git://github.com/schacon/grit.git new
Checking the status

To get the status of the git, type the command git status.Then you should see something like this.

$ git status
# On branch master
nothing to commit (working directory clean)
Add a new file README to your project. If the file didn’t exist   before, and you run git status, you see your untracked file like this:
$ vim README
$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#   README
nothing added to commit but untracked files present (use "git add" to track)
Tracking a file

To begin tracking, use git add. Now on running the command git status, you will get  something like so:
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#
Staging a modified file

Modify a file which is already tracked and then try the command. You will get something like this:
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#
#   modified:   hunter.rb
#

Now this shows the file 'hunter.rb' is modified but not yet staged. To stage it, run the command git add (Multipurpose command- Used for tracking, staging and to do more) and then git status.
$ git add benchmarks.rb
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   new file:   README
#   modified:   hunter.rb
#

If you modified the file 'hunter.rb'. To see the difference between the modified and unmodified file, type the command git diff before staging the modified file.
$ git diff
diff --git a/hunter.rb b/hunter.rb
index 3cb747f..da65585 100644
--- a/hunter.rb
+++ b/hunter.rb
@@ -36,6 +36,10 @@ def main
           @commit.parents[0].parents[0].parents[0]
         end

+        run_code(x, 'commits 1') do
+          git.commits.size
+        end
+
         run_code(x, 'commits 2') do
           log = git.commits('master', 15)
           log.size
Committing a file


The simplest way to commit is to type the commit message inline with the command git commit after -m flag.
$ git commit -m "Story 182: First commit"
[master]: created 463dc4f: "First commit"
 2 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 README
Removing files

To remove a file from Git, you have to remove it from your tracked files and then commit. The git rm command does that and also removes the file from your working directory.
$ git rm pythonhunter.rb
rm 'pythonhunter.rb'
$ git status
# On branch master
#
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       deleted:    pythonhunter.rb
#
Renaming files

To rename a file, run a command git mv and run command git status to get something like this:
$ git mv pythonhunter.txt hunter
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       renamed:    pythonhunter.txt -> hunter
#
Adding remote repository

To add a remote repository, run the below command.
$ git remote add origin git@github.com:rasheedh/Photo-Editor.git
Where 'git@github.com:rasheedh/Photo-Editor.git' is the SSH url(Generating SSH key).

Pushing to remote

If you want to push your master branch to your origin server, then you can run this to push your work back up to the server:
$ git push origin master

[Expecting Your Valuable Comments]
Thank You

No comments:

Post a Comment