Git for Developers

This article provides information regarding how to setup Gitlab as a developer.

Detailed Information

Table of Content

Setting up Gitlab

showing the GitLab Enterprise Edition login window and the location of the single sign-on button.

  • Enter your credentials and you are in!

Back to Top

Create Gitlab Personal Access Token:

  • Log in with UMS account
  • Click settings on the upper right corner 
  • Select access tokens from the User Settings
  • Create a new personal access token by giving it a name. Select "Scopes", but the expiry date is optional.
  • Click the create personal access token button

showing the GitLab personal access token screen and the location of the create personal access token button.

  • Copy the personal access token in a notepad. Don't forget to save the token, or you won’t be able to access it again one the page is refreshed or closed.

showing the GitLab personal access token screen and the location of the Personal Access Token information.

Back to Top

SourceTree for Gitlab:

  • Obtain Sourcetree from here: https://www.sourcetreeapp.com/
  • Download "Server" version of Sourcetree (if you haven't done so.)
  • Create a Bitbucket account when prompted with UMS credentials.
  • Open Sourcetree application and click on Add an account.

showing the SourceTree Remote repositories window and the location of the add account button.

  • Hosting Service: choose "gitlab EE" 
  • host URL: https://gitlab.its.maine.edu/
  • Preferred Protocol: SSH
  • Click "refresh personal access token"
  • You will get a popup window that says, enter your username and password

showing the pop-up window to enter your login information.

  • Enter your username 
  • Enter personal access token (from the previous step) as your password
  • If login succeeds, you will see "Authentication OK"

showing the SourceTree Remote repositories add account screen with Authentication OK showing.

  • Once gitlab is intergrated with Sourcetree, you will see the following screen:

showing the Remote repositories window with the sourcetree successfully added.

  • Delete "Bitbucket" account since you will not use it.

Back to Top

Git for Windows:

  1. Go to https://gitforwindows.org/ and click download
  2. Check all boxes and click 'Next'
    showing the Git Setup select components window with all boxes selected.
  3. Pick whichever you like (If you prefer UltraEdit, select other) and click 'Next'.
    showing the Gitlab setup choosing the default editor used by Git window.
  4. Pick "Git from the command line and also from 3rd party software" and click 'Next'.
    showing the Gitlab set up Adjusting your PATH environment window with GIT from the command line and also from 3rd-party software selected.
  5. Pick "Use the OpenSSL library" and click 'Next'.
    showing the Gitlab setup Choosing HTTPS transport Backend window with Use the OpenSSL library selected.
  6. Pick "Checkout as-is, commit as-is" and click 'Next'.
    showing the Gitlab setup Configuring the line ending conversions window with checkout as-is, commit as-is selected.
  7. Pick "Use MinTTY (the default terminal of MSYS2)" and click 'Next'.
    showing the Gitlab setup Configuring the terminal emulator to use with Git Bash window with Use MinTTY selected.
  8. Click the first two boxes and click 'Install'. Wait for a couple of minutes.
  9. Click "Launch Git Bash" box and click "Finish"
    showing the final Gitlab setup window.
  10. You will see new window for Git Bash.
    showing an example of a GIt Bash window.

Back to Top

Git Command Line Instructions:

The following commands will help upload existing files from your local machine 

Git global setup

git config --global user.name "your user.name"
git config --global user.email "youremail@maine.edu"

Create a new repository

git clone git@gitlab.its.maine.edu:YourUserName/YourNewProject.git
cd YourNewProject
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin git@gitlab.its.maine.edu:YourUserName/ExistingProject.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.its.maine.edu:YourUserName/ExistingProject.git
git push -u origin --all
git push -u origin --tags

Git Workflow commands

git init //initialize a folder to git
git add filename //move the file from unstaged to staged
git rm --cached filename //moves it from staged to unstaged
git reset filename //moves it from staged to unstaged
git add . //will add all files under current directory
git add --all //find all new and updated files everywhere throughout the project and add them to the staging area

Powershell/Linux commands

ls //list non-system files in directory
ls -a //lists all folders and files
cd folder //changes directory into a folder
cd .. //going one level up in folder structure
mkdir folder //makes a directory

Back to Top

Environment

  • Gitlab