GitLab (Git repository)
We provide a Git repository server:
Git repositories allow you to manage your code:
- collaborate with other users
- manage versioning, hence allowing to come back to a previous version
- create different versions of your code (branches / forks)
- have a secure storage location for your code
- make it easy to deploy on another server (simple clone action)
Short introduction on the use of Gitlab
Let’s assume you have some code in the directory /home/users/<username>/mycode/ and you want to create a git repository with this code:
- Go and connect to gitlab: https://gitlab.act.reading.ac.uk
- If not already setup, you’ll need to create an ssh-key to later connect to git-lab from the linux servers. Follow instructions here.
Note: it is possible not to use ssh keys, but you’ll then have to put your credentials each time you do a synchronizing action with the server; you’ll also have to use the https git reference. This way of doing is not described in the following.
- go to your /home/users/<username>/mycode/ directory on a server (e.g. the cluster)
- check that git is running on this server:
- cd to your directory and start git on this directory:
- Add all the files to your git repository and stage the files (commit):
git add .
git commit -m "initial commit"
- now you can push this directory to gitlab. This will create a new project:
git push --set-upstream firstname.lastname@example.org:<your username>/<your project name>.git master
Then, as stated, run:
git remote add origin email@example.com:<your username>/<your project name>.git
- The new created project is private by default. Go to the project via a web browser (https://gitlab.act.reading.ac.uk/<username>/<project name>) and share or make it public if you need to.
- It is good practice to add a readme.md file at the root of your directory. It will be used by default to describe your project. Read more…
Readme files can have some text formatting (markdown). Follow the instructions here.
Basic git commands
Working on a code is usually a 3 steps action:
- Edit your code locally
- Stage and Commit the changes. Comment and changes still recorded locally.
- Push the changes to the gitlab repository
Find the related commands below:
View the changes you’ve made
It’s important to be aware of what’s happening and the status of your changes. When you add, change, or delete files/folders, Git knows about it. To check the status of your changes:
To view the differences between your local, unstaged changes and the repository versions that you cloned or pulled, type:
Add all changes to commit
To add and commit all local changes in one command:
git add .
git commit -m "COMMENT TO DESCRIBE THE INTENTION OF THE COMMIT"
Send changes to https://gitlab.act.reading.ac.uk
To push all local commits to the remote repository:
git push REMOTE NAME-OF-BRANCH
For example, to push your local commits to the master branch of the origin remote:
git push origin master
Read more git commands here