The main difference between the subversion and git is while with the subversion, the communication is direct between the local directory and the server, in git, there is a local repository where the code is saved.
- Subversion: Local copy <-> Remote repository
- Git: Local copy <-> Local repository <-> Remote repository
To use git, you can follow several steps:
1. Set up git and test git:
I found really good guides done by the guys of GitHubs, so I am going to link them:
- Windows: http://help.github.com/win-set-up-git/
- Linux: http://help.github.com/linux-set-up-git/
- Mac OS X: http://help.github.com/mac-set-up-git/
2. Create a new project or join to a existence project
Once git is installed and correctly tested, you have two options: Create a new repository or use an existence one. In both cases you have to make sure that the remote server has your public key created in the Step 1 of this guide.
2.1 Create a new repository
Basically you creates a new folder and you use the command
to create a local repository. More information here: http://help.github.com/create-a-repo/
2.2 Join to a new repository
In case someone else has already created a repository and you want to join it, you can use the command
git clone username@server:serverUserName/directory
to download the repository from the remote server to the local directory. For example:
git clone firstname.lastname@example.org:username/Spoon-Knife.git
where username is your username in the github server.
This options is equivalent to the command checkout of SVN.
This options is equivalent to the command checkout of SVN.
For more information: http://help.github.com/fork-a-repo/
3. Use git commands
I am going to list the commands in git that could be useful. You may be familiar with someone of them because they are similar to the commands in Subversion (SVN)
git commit -a -m "message"
It commit the actual changed to the local repository, which is stored in your own machine. Since the remote repository is what most of the people want to save changes, you should use the command push for it.
The option -m is used to directly input the log without using any text editor.
The option -a is used to commit all the changes from all the files. This is specially important when the user remove a file because with this option, all the files removed with the command rm will be also removed from the repository.
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-commit.html
git remote add remoteRepositoryName userName@UrlOfTheServer:localDirectory.git
This command is used to manage the remote repository. At beginning you should set the direction of the remote directory. The sentence is shown above. Make sure that the local directory ends in ".git".
After the remote directory is set, you can always modify it by editing the config file in the directory .git (.git/config).
Of course you can set several remote directory by using this command several times, but make sure that they have different names.
For example, this is the command to add my git repository in gitHub:
git remote add origin email@example.com:jiahaoliuliu/Hello-World.git
Notice that I have used "origin" for the name of the remote repository. This is because the command push which is used to upload the content of the local repository to the remote repository could be used without type the name of the remote directory. It assume that the local directory is the one in the configuration file which is called "origin".
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
git push remoteRepository LocalDirectory
This command commits the last version in the local repository to the remote repository. Normally the local repository is consider master and the remote directory consider origin. So, normally this command is used like:
git push origin master
If you have set the name of the remote repository as "origin", this command could be shorted and used like:
It automatically looks for in the file .git/config the remote repository called "origin" and commit the changed on it.
More information here: http://kernel.org/pub/software/scm/git/docs/git-push.html
git pull origin master
This command works like the command update of subversion. It is used to obtain the last version of the remote repository and save it to the local repository.
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-pull.html
git statusThis command works like svn status and it checks the actual status of the repository. As in subversion, it is relative to the directory. The status could be:
- ' ': unmodified
- A: Added
- C: Copied
- D: Deleted
- M: Modified
- R: Renamed
- U: updated by unmerged
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-status.html
This command is equivalent to the command log of SVN. It shows you all the logs sorted by time that has been uploaded when the command commit has been executed. More or less the lines could be like this:
Author: Jiahao Liu Liu <firstname.lastname@example.org>
Date: Mon Aug 29 15:12:36 2011 +0200
change a bit readme file
It includes a hash code, the author, the date of commitment and the logs.
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-log.html
Add new files
git add fileName
In order to keep track about any file in the repository, it must be explicitly added with this command. It could also add a directory. In such case, all the files in such directory will be added recursively.
After add new files, don't forget to do commit and push. Otherwise, the changes won't appear in the remote repository.
More information here: http://kernel.org/pub/software/scm/git/docs/git-add.html
There are two ways to remove a file:
git rm fileDir/fileName
This command removes the file from the directory and notice it to the local repository. Then, with the command git commit, the removed files will be also removed from the repository.
The second command remove the file without any notification to the local directory. Then, when the command git commit is used, the option "-a" must be added. With this option, when git upload any change to the local repository, it checks also all the changes from all the files under the directory and also removed files.
More information here: http://www.kernel.org/pub/software/scm/git/docs/git-rm.html
For more complete information about git, you can visit:
For who come from SVN, this guide will helps you better: