Getting started with git

Git configuration using command prompt ::


1. Download and install latest version of git from

2. After installation, edit git configuration file using command prompt.


git config --global "Your name"
            git config --global Your Email

git config --global core.editor emacs

git config --global merge.tool vimdiff


3. Check your settings

git config --list


4. From time to time there are files you don't want git to track.So that you can ignore those files using .gitignore file. Add selected files into the .gitignore file and add it to the gitconfig file.


To add this to your config, run git config --global core.excludesfile ~/.gitignore_global


5. Now your environment is ready to use git.


Choose your action from following::


* Initializing a repository in existing directory::

# Create an empty directory in your working area/local drive or choose an existing project directory to initialize.

# On terminal, go to the directory and run, git init.


* Cloning existing directory::

Run, git clone [url] e.g git clone git://

## url - repository url in git where project file exists.


Now you have a git project to work with git.

* Check project status from local directory(master branch -- in terms of git)

Run, git status

## display your local changes. A- added, M - Modified, D -Deleted, C- conflict

git status -s  ## Display changed file names and statuses only

* Tracking new file::

run, git add . ## this will track all newly added files and prepare them to commit

      git add [filename] ## to track individual file.


* Get differences::

You can check the differences among branches.

run , git diff  ## show diff of unstaged changes

       git diff --cached  ## show dif of staged and unstaged changes.

       git diff HEAD    ## Show diff of working directory and last commit

       git diff --stat       ## show summary of changes instead of a full diff


* Record changes::

run, git commit  ## records a snapshot of local changes.

git add . && git commit -a -m “Your commit message”

## this will add untracked file into git index and will commit all changes into the intermediary branch origin/master. This will record a change and add it to the git database.This will not update your code to the origin or git repository. Commit message is mendatory.


* Add local changes to the git repository::

After every commit , you must run following line to update server or origin.

git push


* Undo Changes::

git reset  ## Undo changes and commit.

git reset HEAD ## undo the last commit and unstage the files

git reset --soft ##undo the last commit

git reset --hard ##undo the last commit, unstage files AND undo any changes in the working directory

* Override server files with your local::

git checkout [directoryname]

git checkout [filepath]


* Receives update from server::

git fetch  

## synchronize you with another repo, pulling down any data that you do not have locally and giving you bookmarks to where each branch on that remote was when you synchronized.


git pull  

## fetch from a remote repo and try to merge into the current branch.This will update your local files with server files.


*Inspection and Comparison::

git log

## Displays your commit history

git log --oneline  ## commit history in one line

git log -p ## commit history with changes.


* Resolve Conflict ::

several options you have to resolve conflict.

# you can checkout previous update of the conflicted file.To do this,

run, git checkout [filename]

# you can reset your code base with server.To do this,

run, git reset --hard


git checkout --theirs [filename] ## get server update of the file

git checkout --ours [filename] ## update server with your changes.

then commit and push.


* Clean Up local directory::

run, git gc  ## will remove garbase file from local directory.


For further details,



Leave a Comment

You must be logged to add a comment !