training:git
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
training:git [2018/06/13 11:31] – created xavi | training:git [2018/06/13 11:59] (current) – xavi | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ## Git | + | ###Git course (Beginners) |
- | 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. | + | Here is the documentation used in the course. Depending on your SO download the pdf that you need. The only difference is the installation process. |
- | It is installed in the cluster so you can use it in your folders. Also there was a training session | + | If you haven' |
- | ## 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: | + | ###Windows users |
- | #### Check ssh-key | + | {{ : |
- | **linux** | ||
- | $ cat ~/ | + | ###Linux and Mac users |
+ | {{ : | ||
- | **windows** | ||
- | |||
- | type %userprofile%\.ssh\id_rsa.pub | ||
- | |||
- | |||
- | If it generates something like this you can skip ' | ||
- | |||
- | |||
- | | ||
- | |||
- | |||
- | #### Create a ssh-key: | ||
- | |||
- | **linux** | ||
- | |||
- | $ ssh-keygen -t rsa -C "< | ||
- | |||
- | |||
- | **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 ' | ||
- | |||
- | ## 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 " | ||
- | $ git config --global user.email " | ||
- | |||
- | |||
- | 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 ~/ | ||
- | ~/git_repo$ | ||
- | |||
- | |||
- | Or if you already have code in GitLab and want to import it in a directory use the command "git clone" | ||
- | |||
- | |||
- | ~/ | ||
- | |||
- | |||
- | ## Using Git | ||
- | |||
- | Now that Git is configurated we can start to upload our scripts/ | ||
- | |||
- | ### Status | ||
- | |||
- | This is very useful to know the current status of our files. | ||
- | |||
- | ~/ | ||
- | On branch master | ||
- | Untracked files: | ||
- | (use "git add < | ||
- | |||
- | 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: | ||
- | |||
- | ~/ | ||
- | |||
- | |||
- | Or selected files: | ||
- | |||
- | |||
- | ~/ | ||
- | |||
- | Again git status: | ||
- | |||
- | ~/ | ||
- | On branch master | ||
- | |||
- | Initial commit | ||
- | |||
- | Changes to be commited: | ||
- | (use «git rm --cached < | ||
- | |||
- | new file: | ||
- | new file: | ||
- | |||
- | |||
- | ### 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(+), | ||
- | | ||
- | | ||
- | |||
- | |||
- | ### Add + commit | ||
- | |||
- | To save time we can add and commit a file at the same time: | ||
- | |||
- | |||
- | ~/git_repo$ git commit -a -m " | ||
- | |||
- | |||
- | ### Push | ||
- | |||
- | This is the final step to upload our commited files to the repository | ||
- | |||
- | |||
- | ~/ | ||
- | |||
- | 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:// | ||
- | | ||
- | |||
- | |||
- | And now the files are saved in GitLab. |
training/git.1528889470.txt.gz · Last modified: by xavi