- 1 Introduction
- 2 Installing Git
- 3 Configure Git (one time only)
- 4 Using 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 is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenientstaging areas, and multiple workflows.” http://git-scm.com/
For installation tutorial of Git on:
Configure Git (one time only)
For setting your name with git, so that it can label the commits you make:
git config --global user.name "Your Name" git config --global user.email "email@example.com"
Start a repository
Start your own local repository, in every folder, is very easy. goto a folder you would like to start repository inside (like inside your project in /var/www/html) and type at bash:
this will create a .git folder inside your folder which saves all the data for your repository. you can delete the .git folder now to delete your local repository and return the folder to what it was before the git init command.
you can use the command:
anytime you want to view your local git status (your need to be inside the project folder, or any subfolder of it, for this command to work)
Beside the social benefits of git, local repository helps you track versions of your files. compare them, and restore older version if needed. when git init command creating the .git folder in the first time, it doesn’t track no file. to add files for track you need to use the
git add <filename>
for example you can create an empty (or not) file called README.MD and type:
git add README.MD
you can use wildcard (such as git add *.conf). this way you can add files to the current commit, and when you ready type:
you need to provide a commit description. using vim by default (can be changed), and you updated your repository with you first commit.
You can also add the commit description as a parameter:
git commit -m "My initial commit"
to commit all changes you can use:
git commit -a
to see commits log use:
to commit all changes you can use:
Clone a repository
the following example will cover this topic clearly.
git clone https://github.com/WordPress/WordPress
this line will create a folder wherever you are called WordPress and clone from wordpress repo all it’s files. you will a .git folder also, which mean you can continue now with your local repository, and even update the source if you have the permission to do so.
to update your local version with the server later:
Clone local repository
You can easily create a clone of your local repo and git pull changes from it:
git clone --no-hardlinks /path/to/repo
Reset Changes from last commit
to reset all the changes you made from the last commit just use:
git reset --hard
Check Difference from last commit
to see the changes made in your git from the last commit use:
‘Q’ for exit. 😉
Create A Repo – goto New Repository page in github and create your new repo. this tutorial is for public & free repo.
you can set a README.MD file to be clone ready immediatly. the following is for a new repo without README.MD:
after you created a new repository you need to git it to a folder.
if you want to start your project now, follow inside new directory:
touch README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/<your-user-name>/<project-name>.git git push -u origin master
if you already have a project your want to create the repo from just go inside your folder, git init it like above, git add neccesary files (you can use wildcard!) and then resyne the last three line above.
if you have a local repo which you want to link to your new online repo just use the last two lines of the bash code above.
* more info: Create A Repo tutorial on github
Push/Pull from/to repository
to push your updates to the server:
to update your local version with the server is the same:
Those are the basics of Git. you can do a lot more with version control and collaborate with others.