Difference between revisions of "Git Tutorials/Creating and Changing Repositories"

From HPC Wiki
Git Tutorials/Creating and Changing Repositories
Jump to navigation Jump to search
Line 11: Line 11:
 
* You have installed [https://git-scm.com/ Git]
 
* You have installed [https://git-scm.com/ Git]
 
* You have a folder (we will call it ''MyFolder''), that you want to put under revision control
 
* 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<syntaxhighlight>user@HPC.NRW:~$ git config --global user.name "Your Name Comes Here"
 +
user@HPC.NRW:~$ git config --global user.email you@yourdomain.example.com</syntaxhighlight>
  
Once those conditions are met, go into ''MyFolder'' and initialize the repository by entering (<syntaxhighlight lang="bash" class="nowrap" inline>yellow highlighting used to emphasize output</syntaxhighlight>)
+
Once those conditions are met, go into ''MyFolder'' and initialize the repository by entering
  
{| class="wikitable" width="50%"
+
<syntaxhighlight line>
|
 
<syntaxhighlight lang="bash" highlight=4>
 
 
user@HPC.NRW:~$ cd MyFolder
 
user@HPC.NRW:~$ cd MyFolder
 
user@HPC.NRW:~MyFolder/$
 
user@HPC.NRW:~MyFolder/$
user@HPC.NRW:~MyFolder/$ git ini
+
user@HPC.NRW:~MyFolder/$ git init
 
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 fill it with content by using the <syntaxhighlight inline>git add</syntaxhighlight> command. You can simply add the whole directory with
 +
 
 +
<syntaxhighlight line>
 +
user@HPC.NRW:~MyFolder/$ git add .
 +
</syntaxhighlight>
 +
 
 +
if you want to add one or more particular files you can do this through
 +
 
 +
<syntaxhighlight line>
 +
user@HPC.NRW:~MyFolder/$ git add someFiles*
 +
</syntaxhighlight>
 +
 
 +
which in this case would add any files beginning with ''someFiles'' into the repository (e.g., ''someFiles2'' or ''someFilesWithMoreTextAndNumb3rsAtTheEnd'').

Revision as of 15:32, 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 some simple 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. 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.

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 (line 4 above), but currently it is still empty. You need to fill it with content by using the git add command. You can simply add the whole directory with

user@HPC.NRW:~MyFolder/$ git add .

if you want to add one or more particular files you can do this through

user@HPC.NRW:~MyFolder/$ git add someFiles*

which in this case would add any files beginning with someFiles into the repository (e.g., someFiles2 or someFilesWithMoreTextAndNumb3rsAtTheEnd).