Gitlab - Getting Started: Difference between revisions

From Computer Science at Indiana State University
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 72: Line 72:
'''Pull''' - To pull/download updates that have happened (by others), you use <code>git pull</code>.
'''Pull''' - To pull/download updates that have happened (by others), you use <code>git pull</code>.


'''Merge''' - When you ready to have your changes merged in to the main branch of the project, ask the owner of the project to check your branch.  When the owner is ready for it, the owner can run the following commands.
'''Merge''' - When you are ready to have your changes merged in to the main branch of the project, ask the owner of the project to check your branch.  When the owner is ready for it, the owner can run the following commands.
<pre>
<pre>
git branch main        # owner is working in the main branch
git branch main        # owner is working in the main branch
git merge branch_name  # merge your branch into the main branch
git merge branch_name  # merge your branch into the main branch
</pre>
</pre>
=Course Assignment=
The following is a list of steps to complete if you are just starting with using ISU's gitlab server for a course assignment.
# Install git on your computer from https://git-scm.com/install/
# Note: if given the option for what the default editor for git should be, you probably don't want it to be vim. On Windows, Notepad is easier to use.
# Follow the instructions at https://docs.gitlab.com/user/ssh/ to generate a private and public key to use for logging into git.indstate.edu. Follow the instructions also to upload your public key into your account at git.indstate.edu (note - do not put it at gitlab.com, put it on git.indstate.edu). The key files are probably stored in your home directory and in a subdirectory there named ".ssh". That will probably be a "hidden" directory, so check online about how to show hidden files on your operating system (e.g., on Mac, type cmd-shift-.).
# Edit your ssh configuration on your computer so it knows which key to use for git.indstate.edu. See https://cs.indstate.edu/web/index.php/Gitlab_-_Getting_Started#SSH_Keys for the file to edit and the text to use.
# In the terminal, set your name and email with git:
#:<code>git config --global user.name "Your name"</code>
#:<code>git config --global user.email "your email address"</code>
# In the terminal, browse to the directory where you want to store this project.
# Still in the terminal, run this command to clone the repository: <code>git clone git+ssh://git@git.indstate.edu/PATH_TO_THE_PROJECT</code>
# Then: <code>cd PROJECT_DIRECTORY</code> (will depend on what project you are cloning)
# Create your own branch, named after your sycamore id. For Jeff Kinne, that would mean replacing YOUR_SYCAMORE_ID with jkinne everywhere below:
#:<code>git branch YOUR_SYCAMORE_ID</code>
#:<code>git checkout YOUR_SYCAMORE_ID</code>
#:Note that we could have used some other name for the branch other than your sycamore id, but using the sycamore id makes it easy to tell which branch is yours.
# Work on the assignment, doing whatever you are supposed to do. You should frequently commit and push changes (this saves them and also lets the instructor see the progress you are making).
#:<code>git add ANY_FILES_THAT_HAVE_BEEN_MODIFIED_THAT_YOU_WANT_TO_COMMIT</code>
#:<code>git commit</code>
#:<code>git push --set-upstream origin YOUR_SYCAMORE_ID</code>
# When you are done, depending on the assignment, you might do a merge request to merge your changes into the main branch of the project. If so, you go to https://git.indstate.edu/PATH_TO_THE_PROJECT and change to your branch.
#: Click on Merge requests on the left. Then click on New Merge Request.
#: For the Source branch, put your branch (YOUR_SYCAMORE_ID). For the Target branch put main.
#: When prompted for the Assignee and Reviewer, put your instructor.
#: Click through to make the merge request.
#: Do NOT approve the merge request, that will be for your instructor to do.
=Administration=
On ISU's gitlab instance, a few common things that are done...
* Create a group for the course and term (e.g., CS 473/573 fall 2026). After each student in the course logs in to git.indstate.edu once, you can add them to the course group with their role as "Developer" (this allows them to create their own branches and push changes).
* Set the main branch so the students (with "Developer" role) cannot approve merge requests. As of 2026, you go to Settings, Repository, Protected Branches, and change the "Allowed to push and merge" setting so it is "Maintainers" only (and does not include "Developers").

Latest revision as of 14:47, 6 October 2026

This page is part of Programming and CS - Getting Started

Git

Git is a version control system that can be used to keep track of your files (programming code, but also other files as well).

Two of the most popular installations of git (as of 2020) are github and gitlab. When Microsoft purchased github, it became fashionable to prefer gitlab. Github allows for projects to be hosted on their servers. Gitlab allows for hosting either on their servers or to run a local installation of gitlab on ones own servers.

Of late, we have hosted projects using gitlab either on gitlab's servers or on ISU's local installation of gitlab.

Account Setup

On gitlab.com - Account setup on gitlab.com is just like any other website. You create a free account, choose your username/password, etc. The account is yours and is not tied in any particular way to ISU. You can give access to your projects in much the same way as you give access to files on google drive, onedrive, dropbox, etc.

On git.indstate.edu - ISU's local installation of gitlab is at https://git.indstate.edu/. For this system you use your ISU portal id and password. You do not need to create an account. The first time you login into the system, it initializes an account for you. CS courses and ISU CS projects in general tend to use ISU's local installation because we can tie access based on course rosters, etc.

SSH Keys

You will normally want to have SSH keys setup so that you can interact with the git server without having to enter a username and password. Instructions are here: https://docs.gitlab.com/user/ssh/

You will need to edit your ssh configuration so that it knows which key to use when connecting to git.indstate.edu. On a Mac or Linux, edit the file ~/.ssh/config and put a section like this:

Host git.indstate.edu
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/git_indstate_id

You should replace the name git_indstate_id with whatever filename you used for the private key. On Windows, the file should be in your home directory (normally C:\Users\YOUR_USERNAME) and then .ssh/config (so, similar to where it is for Mac and Linux).

Note - for editing the config file, you should use a plain text editor (Notepad on Windows, TextEdit on Mac, or something nicer; not Word).

Note - you will need to enable the ability to see "hidden" files. On Mac, you press cmd-shift-. to see hidden files in Finder. On Windows, in File Explorer you need to: click the triple dots near the top right, click Options, click View, select "Show files, folders, and drives", and also unselect "Hide extensions for known file types".

You can clone a repository from git.indstate.edu using a command like this: git clone git+ssh://git@git.indstate.edu/ect-437-fall-2026/hello-class.git, but where you would replace the link with whatever repository you are cloning.

Windows - Using Putty

If you are on Windows and are getting an access error when you tro to run the git clone command, it might work by changing the configuration for git to use a different program for ssh. You can try the following.

[Environment]::SetEnvironmentVariable("GIT_SSH", "plink.exe", "User")
git config --global core.sshCommand "plink.exe"
  • Open the app PuttyGen (that is installed along with Putty). Click "Load", and load your private key file (id_ed25519 if you used default settings); you will need to change the Filename selector to "All Files" rather than "Putty Private Key Files". Then click "Save private key", and save the private key in the ppk format (and store it in your .ssh directory); use the same filename but put ".ppk" at the end.
  • Open the app Pageant (that is also installed along with Putty). This runs in the background, so nothing will appear on the screen. Look in your system tray for a new icon. Click on the Pageant icon in the system tray, right-click on it, and click "Add key". Select the ppk file you just produced.
  • Close your terminal windows and open a new one. Try running the git pull command again. Note that you may need to delete the "hello-class" directory if it was created by trying to run the git pull previously (even if it fails, it might make the directory).

Getting Around

Whether you are using gitlab.com or git.indstate.edu, the functionality and "how to get around" is about the same. You have two main methods for using either.

Web browser interface

You can view projects within your web browser. How to get around is fairly intuitive - as is the case with any web page, you look around and click around to see what different things do. When you have something specific you want to do but don't see how to do, you ask the internet or ask your instructor (and we may update this wiki to give instructions on how to do it).

Terminal interface

Git allows for downloading/uploading/etc. files in your projects from the terminal. In order to do this, you need to (a) have a git client installed on your system, (b) understand the terminology that git uses for keeping track of files and the steps in using git to download/update/upload files, (c) make it so.

Some reading material about using git - https://www.tutorialspoint.com/git/index.htm

Vocab / Cheat Sheet

Workflow

A common use case is that you will need to download someone else's (e.g., instructor's) gitlab project, create your own version of some part of the project, test/debug your version of the project, eventually put in a request to update the main project with your code. The steps involved in that workflow.

Clone - To download the current version of the project you (a) browse in your terminal to the directory where you want to have the project code, (b) run git clone url_to_project

Branch - If a branch has already been created for you, then you can set that as your active branch by running git checkout branch_name. If a branch has not yet been created for you, you run git branch branch_name to create a new branch. In either case, you have a branch of the project to work within.

Do your work - You work on your files locally - test, debug, etc.

Stage/Commit/Push - To save your work to the remote server, you need to stage, commit, and push. You can stage/commit batches of changes, or do a stage/commit for each discreet task accomplished. If you are working in some_file.txt, you would run the following sequence of commands.

git add some_file.txt  # this "stages" the file to be part of the next commit
git commit -m "Some updates to the file" # This commits, will be a permanent record of this version of the file
git push               # sends all committed changes to the remote server

Note that the push may ask for login information to the remote server. If you have an ssh key configured for the project (see section above), then you won't be asked for login information.

Pull - To pull/download updates that have happened (by others), you use git pull.

Merge - When you are ready to have your changes merged in to the main branch of the project, ask the owner of the project to check your branch. When the owner is ready for it, the owner can run the following commands.

git branch main        # owner is working in the main branch
git merge branch_name  # merge your branch into the main branch

Course Assignment

The following is a list of steps to complete if you are just starting with using ISU's gitlab server for a course assignment.

  1. Install git on your computer from https://git-scm.com/install/
  2. Note: if given the option for what the default editor for git should be, you probably don't want it to be vim. On Windows, Notepad is easier to use.
  3. Follow the instructions at https://docs.gitlab.com/user/ssh/ to generate a private and public key to use for logging into git.indstate.edu. Follow the instructions also to upload your public key into your account at git.indstate.edu (note - do not put it at gitlab.com, put it on git.indstate.edu). The key files are probably stored in your home directory and in a subdirectory there named ".ssh". That will probably be a "hidden" directory, so check online about how to show hidden files on your operating system (e.g., on Mac, type cmd-shift-.).
  4. Edit your ssh configuration on your computer so it knows which key to use for git.indstate.edu. See https://cs.indstate.edu/web/index.php/Gitlab_-_Getting_Started#SSH_Keys for the file to edit and the text to use.
  5. In the terminal, set your name and email with git:
    git config --global user.name "Your name"
    git config --global user.email "your email address"
  6. In the terminal, browse to the directory where you want to store this project.
  7. Still in the terminal, run this command to clone the repository: git clone git+ssh://git@git.indstate.edu/PATH_TO_THE_PROJECT
  8. Then: cd PROJECT_DIRECTORY (will depend on what project you are cloning)
  9. Create your own branch, named after your sycamore id. For Jeff Kinne, that would mean replacing YOUR_SYCAMORE_ID with jkinne everywhere below:
    git branch YOUR_SYCAMORE_ID
    git checkout YOUR_SYCAMORE_ID
    Note that we could have used some other name for the branch other than your sycamore id, but using the sycamore id makes it easy to tell which branch is yours.
  10. Work on the assignment, doing whatever you are supposed to do. You should frequently commit and push changes (this saves them and also lets the instructor see the progress you are making).
    git add ANY_FILES_THAT_HAVE_BEEN_MODIFIED_THAT_YOU_WANT_TO_COMMIT
    git commit
    git push --set-upstream origin YOUR_SYCAMORE_ID
  11. When you are done, depending on the assignment, you might do a merge request to merge your changes into the main branch of the project. If so, you go to https://git.indstate.edu/PATH_TO_THE_PROJECT and change to your branch.
    Click on Merge requests on the left. Then click on New Merge Request.
    For the Source branch, put your branch (YOUR_SYCAMORE_ID). For the Target branch put main.
    When prompted for the Assignee and Reviewer, put your instructor.
    Click through to make the merge request.
    Do NOT approve the merge request, that will be for your instructor to do.

Administration

On ISU's gitlab instance, a few common things that are done...

  • Create a group for the course and term (e.g., CS 473/573 fall 2026). After each student in the course logs in to git.indstate.edu once, you can add them to the course group with their role as "Developer" (this allows them to create their own branches and push changes).
  • Set the main branch so the students (with "Developer" role) cannot approve merge requests. As of 2026, you go to Settings, Repository, Protected Branches, and change the "Allowed to push and merge" setting so it is "Maintainers" only (and does not include "Developers").