Setting Up SDC with GitLab Repositories
The following sections provide instructions for SDC users on setting up GitLab repositories for
committing and sharing their code and any other documents.
GitLab provides an organizational structure of users and repositories managed respectively via
“groups” and “projects” to promote collaboration among teams of SDC users. Groups contain
members with different access levels to their project repositories based on the assigned roles:
GitLab Features:
Share code with specific team members, your entire team, or different research teams that are also using the SDC.
Simplified collaboration with shared read/write access.
Manage multiple repositories that are organized and structured in a logical manner.
Version control and source code management including:
File locking to help prevent conflicts
Users can work from their local copy of the code
Users can branch code to make changes and then quickly merge it after approval
🚪 Log In to GitLab
Within your SDC workstation, open a web browser, then navigate to https://gitlab.prod.sdc.dot.gov. This is the URL to the SDC’s internal GitLab.
In the Sign in page, the LDAP login option is selected by default. Enter your SDC credentials as the LDAP username and password, then click Sign in (in the LDAP Username field, do not enter the “@securedatacommons.com” portion of your SDC username).
The Welcome to GitLab web page is displayed.
Create a Group
In the Welcome to GitLab web page, select Create a group.
The New group form appears. Enter the name for the new group.
Select the Private option under Visibility level to only allow members in the group to see the group and its projects.
Select Create group.
A success message appears indicating that the group was created. You are now ready to add members to the group.
Add Group Members
Users assigned with the “Developer” or “Maintainer” role can add other GitLab members in the
SDC to their groups.
NOTE: SDC users are listed as a GitLab member in the Members panel only after they have
logged into GitLab. If you do not see your SDC colleague listed, please ask them to log in to
GitLab.
In the newly created project web page, click Members from the left navigation menu.
In the “Search for members” text box, start entering the name of the SDC user you want to add; then select the member’s name from the autocomplete list.
Select a role from the next drop-down menu. You can select the “Read more” link to view a comprehensive list of the different available permission levels and their access rights. A summary of the roles’ access types is also shown in Table 1 at the beginning of this chapter.
Select Add to group.
Create a Project
Select the GitLab icon on the upper left to return to the home page.
Select Create a project.
The New project form appears. Enter a name for the project.
Select the Private option under Visibility level, so that the project is only visible to users who are granted explicit access to the project.
Select the Initialize repository with README checkbox to automatically generate a readme file that contains the project’s repository details.
Select Create project.
7. A success message appears indicating that the project repository was created. You are
now ready to add members to the project.
Add Members or Groups to a Project
Select the GitLab icon on the upper left to return to the home page.
A list of your projects appears. Select the name of the project you want to add members
/groups to.Click on Settings and then Members from the left navigation menu.
You can add individual users or entire groups to the project.
Select the Invite member tab to add members individually to the project.
Start entering the project member’s name or email address into GitLab
member or Email address to select from the autocomplete list.Select a role for the project member from the drop-down menu under Choose a role permission.
Click Add to project.
Select the Invite group tab to add an entire group to the project.
Start entering the group’s name into Select a group to invite to select from
the autocomplete list.Select a role to apply for the group from the drop-down menu under Max
access level.Select Invite to grant the group access to the project repository.
🔑 Generate SSH Key
To set up git integration, you need to have an SSH key on your SDC workstation. This key
authenticates your identification to GitLab so that you can push commits to the project
repository.
NOTE: For Windows users, perform the following commands in Git Bash. If Git Bash is not
installed on your Windows workstation, please copy the Git Bash installer, Git-2.19.1-64-
bit.exe, from the Z:\software-distribution folder and then install it.
To store your authentication credentials for git, use a hidden folder called “.ssh.” First,
check to see if the folder exists with ls –a.ls –a
If not, create it using the command mkdir .ssh:
mkdir .ssh
Confirm this works by entering ls –a to see all objects in the current directory. You should see the .ssh listed:
ls –a
Generate a new key to store in this location by typing the following command and then hitting the Enter key:
It will output the following message: “Generating public/private rsa key pair.”
It will ask you where to save the file and to enter a passphrase with the following three
prompts. Hit the Enter key each time (no need to enter anything else) to accept the
defaults.
• “Enter file in which to save the key:”
• “Enter passphrase (empty for no passphrase):”
• “Enter same passphrase again:”After the following confirmation messages, the new SSH key is now stored in the .ssh
folder.
• “Your identification has been saved in /c/Users/SDCusername/.ssh/id_rsa.”
• “Your public key has been saved in /c/Users/SDCusername/.ssh/id_rsa.pub.” The default key file name is id_rsa and is saved under the .ssh folder (e.g.,
C:/Users/[SDCusername]/.ssh/ in Windows; $HOME/.ssh/id_rsa in Linux)You now need to provide the public part of this key to GitLab by copying the “.pub” part
of the key. Here are the different options for copying the public SSH key. Option 1:
On Windows, open the id_rsa.pub file (under the C:/Users/[SDCusername]/.ssh folder) in
a text editor (Notepad) and copy the entire key by using Select All then Copy. Be careful
not to accidentally change anything!
Option 2:
Copy your public SSH key to the clipboard by using one of the commands below
depending on your Operating System: Git Bash on Windows:cat ~/.ssh/id_rsa.pub | clip
WSL/GNU/Linux (requires the xclip package):
xclip -sel clip < ~/.ssh/id_rsa.pub
If using Jupyter, use the head command. Right-click on the output and click copy:
head ~/.ssh/id_rsa.pub
From the GitLab home page, add your public SSH key to your GitLab account:
a. In the upper-right corner, click on your avatar image and then click Settings.
b. From the left navigation menu, click SSH Keys.
c. In the Key field, paste your public SSH key.
d. The Title field will be automatically populated with SDCusername@securedatacommons.com.
e. Click the Add key button.To test whether your SSH key was added correctly, run the following command in your
terminal:ssh -T git@scm. internal.sdc.dot.gov
The first time you connect to GitLab via SSH, you will be asked to verify the authenticity
of the GitLab host you are connecting to. Type “yes” to add the SDC internal GitLab to
the list of trusted hosts.You should see the “Welcome to GitLab, @username!” message.
NOTE: Once added to the list of known hosts, you will not be asked to validate the
authenticity of SDC internal GitLab’s host again. Run the above command once more,
and you should only receive a “Welcome to GitLab, @username!” message.
If the Welcome message does not appear, run SSH in verbose mode by replacing -T with -vvvT to debug the error:
ssh -vvvT git@scm. internal.sdc.dot.gov