Table of Contents
Git
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
It is installed in the cluster so you can use it in your folders. Also there was a training session to learn to use git in your own computer. Check it here
Initial config
SSH-Key
Once you have created a GitLab account you have to generate a ssh-key from your computer, but first check if you already have one running this command:
Check ssh-key
linux
$ cat ~/.ssh/id_rsa.pub
windows
type %userprofile%\.ssh\id_rsa.pub
If it generates something like this you can skip 'Create a SHH-Key' step and go to 'Copy ssh-key':
ssh-rsa loooong alphanumeric string xxxxxxxxxx@ceab.csic.es
Create a ssh-key:
linux
$ ssh-keygen -t rsa -C "<user_name>@ceab.csic.es"
windows
type %userprofile%\.ssh\id_rsa.pub
Copy ssh-key
And now here is the IMPORTANT thing: Copy-paste the key to the 'My SSH Keys' section under the 'SSH' tab in your user profile. Please copy the 'complete
' key starting with ssh-rsa and ending with your username and host. If you want to upload code from other computers you will need to do this in each computer. You can save different keys in your profile.
Configuration
Even if there is only one person working in a project Git needs a name to know who make changes to a project:
$ git config --global user.name "username" $ git config --global user.email "username@ceab.csic.es"
Create or go to the directory where you want to create a Git repository (i.e. git_repo) and run:
~/git_repo$ git ini Initialized empty Git repository in ~/ejemplo_git/.git/ ~/git_repo$
Or if you already have code in GitLab and want to import it in a directory use the command “git clone”. (You can copy this from Project tab in the SSH box)
~/git_repo$ git clone ssh://git@gitlab.ceab.csic.es:9122/<user_name>/<project_name>.git
Using Git
Now that Git is configurated we can start to upload our scripts/files to our repository:
Status
This is very useful to know the current status of our files.
~/git_repo$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed)
new_file.py
nothing added to commit but untracked files present (use "git add" to track)
Add
First Git has to track the file. In other words, it has to notice there is something to add to the repository.
If you want to add all files in the directory:
~/git_repo$ git add .
Or selected files:
~/git_repo$ git add README.md .gitignore
Again git status:
~/git_repo$ git status On branch master
Initial commit
Changes to be commited: (use «git rm --cached <file>...» to unstage)
new file: README.md new file: .gitignore
Commit
With commit we save an actual image of the file and let us write a message. Don't forget to use add before commit.
~/git_repo$ git commit -m "two new files" [master (root-commit) 519caba] two new files 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README create mode 100644 helloworld.py
Add + commit
To save time we can add and commit a file at the same time:
~/git_repo$ git commit -a -m "message"
Push
This is the final step to upload our commited files to the repository
~/git_repo$ git push Counting objects: 5, done. Delta compression using up to 8 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 275 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 1 (delta 0) To ssh://git@gitlab.ceab.csic.es:9122/<user_name>/git_repo.git fa8b3ac..568ecf3 ejemplo_git -> ejemplo_git
And now the files are saved in GitLab.