I finally decided to use GIT for one of my new project. I know this sounds odd given that everybody nowadays seems to use it… Having used SVN for a while the transition should be smooth though. There are a bunch of tutorials on the web and I don’t pretend to create a better one (see e.g. link at the bottom of this page). This post does NOT explain was GIT is or how it compares to other concurrent tools. Instead, it provides some commands I used to start setting my first GIT project.
Creating a project and the basics
First, I created an account on bitbucket (I needed a private repo) where instructions to set up the GIT repository were provided, which was definitely useful.
Starting from scratch, create a directory locally and make it GIT compatible:
mkdir projectName cd projectName git init |
Then, you need to connect your local git (projectName) to the server repository
git remote add origin https://username@bitbucket.org/username/projectName |
Here remote stands for any remote repositories that are hosted on the Internet, locally or in the network.
Note also that if you clone a repository, Git implicitly creates a remote named origin by default. The origin remote links back to the cloned repository. This is not the case here since I started a project from scratch using “git init”.
Therefore, the origin remote has not been created automatically hence the “add origin”.
You can then add new files, add and commit them as if you were using SVN:
echo "# This is my README" >> README.txt git add README.txt # commit your file to the local repository git commit -m "Adding a README file." |
The difference with SVN is that the commit is performed locally. You then need to “push” your repository on the server itself:
git push -u origin master |
Here “master” stands for the name of the branch.
A collaborator can then get the server repository by “cloning” it on his/her local machine:
git clone https://bitbucket.org/username/projectName/ |
And obtain latest updates by “pulling”
git pull |
Like in SVN, you can see the status as follows:
git status |
GIT configuration
Some configuration can be done to have nicer output
git config --global color.ui true git config --global color.status auto git config --global color.branch auto |
By default Git uses the system default editor which is taken from the VISUAL or EDITOR environment variables if set. You can configure a different one via the following setting.
# setup vim as default editor for Git (Linux) git config --global core.editor vim |
Reverting back to previous versions
If you’ve done some local changes (not yet commited) and want to cancel those changes, use:
git checkout HEAD <filename> |
You can replace HEAD by a commit version (found with git log
Merging branches
Here is a nice and complete documentation: GIT doc