Difference between revisions of "Git Tutorials/Creating and Changing Repositories"
Line 3: | Line 3: | ||
{{Syllabus Git Tutorials}} | {{Syllabus Git Tutorials}} | ||
− | Most of the users are only interested in having some kind of revision control for their own code. Therefore, we will start with | + | Most of the users are only interested in having some kind of revision control for their own code. Therefore, we will start with basics, which will allow you to put your code under revision control in a few simple steps and you will also learn how to easily add changes the code (this will be done locally on your harddrive; utilizing GitHub follows later). At first you will need to create a repository for your code. To fully grasp what a repository is, you can read the corresponding Wikipedia page, but for now it is sufficient to think of it as a box into which you will put everything that you want to have under revision control. Additionally, the box contains a list, which tracks everything put into the box, everything taken out of it and any changes made to the objects inside. |
+ | |||
+ | This tutorial will consist of the following phases (we will stick with the box analogy for now): | ||
+ | |||
+ | # Initializing your repository: You '''create''' the box | ||
+ | # Adding files to the repository: You '''note''' on the list what goes in the box and what changes to apply | ||
+ | # Commiting your changes to the repository: You '''put''' the objects and '''apply the changes''' to the box as has been '''noted''' on the list | ||
+ | |||
=== Creating a new repository === | === Creating a new repository === | ||
Line 16: | Line 23: | ||
Once those conditions are met, go into ''MyFolder'' and initialize the repository by entering | Once those conditions are met, go into ''MyFolder'' and initialize the repository by entering | ||
− | <syntaxhighlight | + | <syntaxhighlight lines> |
user@HPC.NRW:~$ cd MyFolder | user@HPC.NRW:~$ cd MyFolder | ||
user@HPC.NRW:~MyFolder/$ | user@HPC.NRW:~MyFolder/$ | ||
Line 22: | Line 29: | ||
Initialized empty Git repository in /home/MyFolder/.git/ | Initialized empty Git repository in /home/MyFolder/.git/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Your repository has been initialized (line 4 above), but currently it is still empty. You need to | + | Your repository has been initialized (see line 4 above). Your box has been created, but currently it is still empty. You need to '''note''' with which content you want to fill the box/repository by using the <syntaxhighlight inline>git add</syntaxhighlight> command. You can simply '''note''' to add the whole directory with |
− | <syntaxhighlight | + | <syntaxhighlight> |
user@HPC.NRW:~MyFolder/$ git add . | user@HPC.NRW:~MyFolder/$ git add . | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | If you want to '''note''' the addition of one or more particular files you can do this through | |
<syntaxhighlight line> | <syntaxhighlight line> | ||
− | user@HPC.NRW:~MyFolder/$ git add someFiles* | + | user@HPC.NRW:~MyFolder/$ git add someFiles* andMore |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | which in this case would '''note''' to add the file ''andMore'' and any files beginning with ''someFiles'' into the repository (e.g., ''someFiles2'' or ''someFilesWithMoreTextAndNumb3rsAtTheEnd''). | ||
− | + | Once you are sure what goes in, it is time to '''put''' it in the box and '''apply the changes'''. The <syntaxhighlight inline>git commit</syntaxhighlight> command is used to '''put''' something in and '''apply the changes''' something. This command has to be accompanied by a message, which describes the changes you have made to the repository. The fastest way to do this is by adding the message directly to the commit through the parameter <syntaxhighlight inline>-m</syntaxhighlight>: | |
+ | |||
+ | <syntaxhighlight> | ||
+ | user@HPC.NRW:~MyFolder/$ git commit -m "Repository/Box has been created and filled with some initial files" | ||
+ | </syntaxhighlight> | ||
+ | This command will be followed by information regarding your commit like the amount of files and changes it contained. At this point, it will also inform you that you have commited to your master branch. Branches will be covered later, so you do not need to worry about them. |
Revision as of 16:24, 27 July 2022
Tutorial | |
---|---|
Title: | Git Tutorials |
Provider: | HPC.NRW
|
Contact: | tutorials@hpc.nrw |
Type: | Online |
Topic Area: | Revision control |
License: | CC-BY-SA |
Syllabus
| |
1. Basic Git overview | |
2. Creating and Changing Repositories | |
3. Branching |
Most of the users are only interested in having some kind of revision control for their own code. Therefore, we will start with basics, which will allow you to put your code under revision control in a few simple steps and you will also learn how to easily add changes the code (this will be done locally on your harddrive; utilizing GitHub follows later). At first you will need to create a repository for your code. To fully grasp what a repository is, you can read the corresponding Wikipedia page, but for now it is sufficient to think of it as a box into which you will put everything that you want to have under revision control. Additionally, the box contains a list, which tracks everything put into the box, everything taken out of it and any changes made to the objects inside.
This tutorial will consist of the following phases (we will stick with the box analogy for now):
- Initializing your repository: You create the box
- Adding files to the repository: You note on the list what goes in the box and what changes to apply
- Commiting your changes to the repository: You put the objects and apply the changes to the box as has been noted on the list
Creating a new repository
Before we start, please make sure that you fulfill the following conditions:
- You have some kind of Linux distribution installed
- You have installed Git
- You have a folder (we will call it MyFolder), that you want to put under revision control
- You have set your identity and email through the two commands
user@HPC.NRW:~$ git config --global user.name "Your Name Comes Here" user@HPC.NRW:~$ git config --global user.email you@yourdomain.example.com
Once those conditions are met, go into MyFolder and initialize the repository by entering
user@HPC.NRW:~$ cd MyFolder
user@HPC.NRW:~MyFolder/$
user@HPC.NRW:~MyFolder/$ git init
Initialized empty Git repository in /home/MyFolder/.git/
Your repository has been initialized (see line 4 above). Your box has been created, but currently it is still empty. You need to note with which content you want to fill the box/repository by using the git add
command. You can simply note to add the whole directory with
user@HPC.NRW:~MyFolder/$ git add .
If you want to note the addition of one or more particular files you can do this through
user@HPC.NRW:~MyFolder/$ git add someFiles* andMore
which in this case would note to add the file andMore and any files beginning with someFiles into the repository (e.g., someFiles2 or someFilesWithMoreTextAndNumb3rsAtTheEnd).
Once you are sure what goes in, it is time to put it in the box and apply the changes. The git commit
command is used to put something in and apply the changes something. This command has to be accompanied by a message, which describes the changes you have made to the repository. The fastest way to do this is by adding the message directly to the commit through the parameter -m
:
user@HPC.NRW:~MyFolder/$ git commit -m "Repository/Box has been created and filled with some initial files"
This command will be followed by information regarding your commit like the amount of files and changes it contained. At this point, it will also inform you that you have commited to your master branch. Branches will be covered later, so you do not need to worry about them.