Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Most Commonly Used Git Commands

usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--   info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help] <command> [<args>]


The most commonly used git commands are:
add            Add file contents to the index
bisect         Find by binary search the change that introduced a bug
branch        List, create, or delete branches
checkout     Checkout a branch or paths to the working tree
clone          Clone a repository into a new directory
commit       Record changes to the repository
diff             Show changes between commits, commit and working tree, etc
fetch           Download objects and refs from another repository
grep           Print lines matching a pattern
init              Create an empty git repository or reinitialize an existing one
log              Show commit logs
merge         Join two or more development histories together
mv              Move or rename a file, a directory, or a symlink
pull              Fetch from and merge with another repository or a local branch
push            Update remote refs along with associated objects
rebase         Forward-port local commits to the updated upstream head
reset           Reset current HEAD to the specified state
rm              Remove files from the working tree and from the index
show           Show various types of objects
status          Show the working tree status
tag              Create, list, delete or verify a tag object signed with GPG

Git: Installation & Setup

Installation:

1) Ubuntu,debian
           sudo apt-get install git-core
2) Fedora,red hat
           yum install git
3) Windows
           http://code.google.com/p/msysgit/
4) Mac OS
           http://code.google.com/p/git-osx-installer 

Setting up Git:

When you first start using Git, there are a few things you will likely want to get setup before you start. Git records your name and email address when you create commits, so you need to tell Git what those are. 

You can use the git config command to set those. If you pass --global, it will save the values in the ‘~/.gitconfig’ file so they are the default for all of your repositories.

User Configuration:

          $ git config --global user.name "Your Name" 
          $ git config --global user.email "YourMail@gmail.com"

Push configuration:

The following command configure Git so that the git push command pushes always all branches which are connected to a remote branch (configured as remote tracking branches) to your Git remote repository. This makes is typical easier to ensure that all relevant branches are pushed.

# set default so that all changes are always pushed to the repository 
         $ git config --global push.default "matching"

Avoid merge commits for pulling:

If you pull in changes from a remote repository, Git by default creates merge commits. This typically undesired and you can avoid this via the following setting.

# set default so that you avoid unnecessary commits 
        $ git config --global branch.autosetuprebase always

Color Highlighting:

       $ git config --global color.ui true 
       $ git config --global color.status auto 
       $ git config --global color.branch auto

Setting the default editor:


       $  git config --global core.editor vim

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.

Git is a distributed system, everyone has their own copy of the source codes.

Distributed version control system:
A distributed version control system has not necessary a central server which stores the data.


The user can copy an existing repository. This copying process is typically called cloning in a distributed version control system.

Typically there is a central server for keeping a repository but each cloned repository is a full copy of this repository. The decision which of the copies is considered to be the central server repository is a pure convention and not tied to the capabilities of the distributed version control itself.

Every local copy contains the full history of the collection of files and a cloned repository has the same functionality as the original repository.

Every repository can exchange versions of the files with other repositories by transporting these changes. This is typically done via the selected central server repository.