Git – Setup repository and basic operation

Since few days I am working on GIT version system. I have mostly worked on SVN system for windows, and its easy to work with as its providing GUI. Its bit difficult to work with GIT (only for initial level).

Today I would like to share some basic knowledge which can help you to start with Git. Some basic commands like Setup repository, push code, add new files, fetch new changes etc…

Setup repository,

mkdir my_project.git
cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP

From local machine, add code / initial push

cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin
git push -u origin master

Its done! repository is created.

Now project contributor can clone and track remote repository (as we do checkout in SVN)

git clone
cd my_project

Adds your new or modified files to the queue to be committed later. Files are not committed yet

git add

Delete file which are not more required in directory

git rm file.php

Commits the files that have been added and creates a new revision with a log.

git commit

If you do not add any files, git will not commit anything. You can combine both actions with git

commit -a

Push your changes to the remote repository.

git push

Update your local copy of a remote branch. This operation never changes any of your own branches and is safe to do without changing your working copy.

git fetch

Pull is context sensitive, so Git will merge any pulled commits into the branch you are currently working in. pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches you may run into frequent conflicts.

git pull

2 thoughts on “Git – Setup repository and basic operation

  1. Pingback: Git – File Rename | Tech Bandhu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s