Version Control with Git
Git is a version control system, which makes it easy to track changes, and revert to previous verison. This guide shows you how to set up a git repository on your NTNU home catalog.
Norsk versjon: Versjonskontroll med Git
All students have the possibility to get a free repository at GitHub.
This article will guide you through how to make and use a git repository from your home area or group area at NTNUs servers, using SSH. After you have created the repository, you can use graphical software like these if you rather prefer that. If you do so, please note that the graphical client to Windows from GitHub does not work optimally with NTNUs home and group areas.
Create a Git repository #
Before you can start to use Git, you must have a repository. This is the place where the files and folders to a project, is located. If you don't have access to a repository, you can create one at one of NTNUs unix servers. To log in there, take a look at our SSH article for a step by step guide on how to do that.
On the stud/ansatt server, type:
username@caracal:~$ mkdir <projectname> username@caracal:~$ cd <projectname> username@caracal:~/<projectname>$ mkdir <projectname>.git username@caracal:~/<projectname>$ cd <projectname>.git username@caracal:~/<projectname>/<projectname>.git$ git init --bare Initialized empty Git repository in <path>
Note down the path, as we're going to use that later.
If you haven't already installed git on your local machine, now is the time:
Installing Git on your own machine #
For linux, run the following commands:
username@<computer-name> ~$ yum install git-core
username@<computer-name> ~$ sudo apt-get install git
For Mac OSX:Install GitHubs client and choose also to install command line tools. An other alternativ is to install git for osx from here. If you already have MacPorts on you mac, you can instead run this command:
username@<computer-name> ~$ sudo port install git-core +svn +doc +bash_completion +gitweb
Initializing Git on your own machine #
Start Terminal on OSX/Linux, or start git shell/msysgit shell on Windows.
Use the command cd (change directory) to navigate to the folder where you want the git repository to be stored.
username@<computer-name> ~$ cd <path to folder where I want my project>
When you have navigated to the designated directory, type:
username@<computer-name> ~/<project path> $ git init Initialized empty Git repository in <project path>.git/ username@<computer-name> ~/<project path> $ git remote add origin email@example.com:<path>
If you don't remember the path on login.stud.ntnu.no where the first repository was created, log on login.stud using ssh, then use the cd command to navigate to that folder. Once you're there, type the command "pwd" to show the current path.
To test that everything works, do your first commit by creating a text file, for example test.txt in the repository (project folder).
username@<computer-name> ~/<project path> $ git add <test fil> username@<computer-name> ~/<project path> $ git commit -m 'Initial Commit' username@<computer-name> ~/<project path> $ git push origin master > Here you will be asked to log in. The password and username is the same as you use on innsida Counting objects: 3, done. Writing objects: 100% (3/3), 224 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To <ntnu-username>@login.stud.ntnu.no:<project path>.git * [new branch] master -> master
Congratulations! You have now created your first repository on your NTNU home folder.
Where can I learn more? #
Githubs Help Section has many simple and good guides.
GitHub/CodeSchool has a great and interactive intro course.