Tuesday 6 August 2019

GIT tutorial


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:
Then, you need to connect your local git (projectName) to the server repository
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:
The difference with SVN is that the commit is performed locally. You then need to “push” your repository on the server itself:
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:
And obtain latest updates by “pulling”
Like in SVN, you can see the status as follows:

GIT configuration

Some configuration can be done to have nicer output
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.

Reverting back to previous versions

If you’ve done some local changes (not yet commited) and want to cancel those changes, use:
You can replace HEAD by a commit version (found with git log )


0 comments:

Post a Comment