1 Git, GitLab and Sourcetree in iOS

1.1 Introduction

      This is an overview and tutorial on how to get started with coding version control and organization. Git is a version control software, Sourcetree is a GUI to interact with Git without having to utilize terminal (iOS) or command line (Windows), though if you are more comfortable using these then feel free to do so. GitLab is an interface which allows for the sharing and editing of code on a server accessible to a team of users. This introductory tutorial will take you through the steps necessary to set up all three using iOS.

Some important nomenclature to understand:

  • CLONING is where you copy a repository stored in GitLab locally on your computer which allows you to then edit its contents. This is the first step to amending any already existing and hosted code.
  • BRANCH
  • FORK
  • COMMIT is where you confirm the local changes you made locally to the document/code. Committing does not send the updated version of the code/documents to GitLab.
  • PUSH is where once you have committed changes you want to update the code/document onto GitLab.
  • PULL
  • MERGE

1.2 Downloading Git, GitLab and Sourcetree

1.2.1 Open a GitLab Account

  1. Navigate to this site and sign in with your SUNet ID

    1. For non-Stanford people we can test out linking projects to regular GitLab accounts. To set up an account navigate here and click “Register”.
  1. To link GitLab and Sourcetree you need to acquire a Personal Access Token (PAT). In order to obtain one click on the user avatar on the top left, select “Preferences” from the drop down, select “Access Tokens” from the menu on the left-hand side and follow the instructions selecting all of the permissions under “Select scopes”.

1.2.2 Downloading Git

  1. Navigate to this site and click “download for Mac” and follow the instructions (which I will summarize below):

    1. In the search bar type “terminal”.

    2. Type “brew install git”

    3. If it states you do not have the function brew then you must go here and follow the instructions (essentially copy and paste “/bin/bash -c”$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” into terminal and then re-enter “brew install git” in terminal.

1.2.3 Downloading Sourcetree

  1. Navigate to this site: https://www.sourcetreeapp.com and click “Download for Mac OS X” and follow the instructions.

  2. To link GitLab and Sourcetree you need to take the PAT (glpat-XzSkzLi3zwQpKxzsaX3V) obtained above and enter it when setting up a new account.

    1. In Sourcetree, during setup click “connect” and “Add…” under the “Accounts” window click “Accounts”. For Stanford, under “Host” select “GitLab Enterprise” and enter the url https://code.stanford.edu, your username and your PAT as the password while under “Protocol” HTTPS is selected. For non-Stanford people the “Host” selection should be “GitLab.com” with remaining options same as in i. above.

    2. Set GitLab as default and exit out of this screen.

1.3 Basic Tutorial For Code Version Control

1.3.1 Create a New Project

  1. In GitLab go to “Menu” in the top left corner and select “Projects” and then “Create New Project” and finally “Create blank project”.

  2. Keep “Initialize repository with a README” under “Project Configuration” selected. This will then create all the initial files needed for a repository on GitLab and will then allow you to clone this repository to a local location of your choosing on your computer.

  3. Open Sourcetree and select “Remote” on the top left-hand side, then highlight the GitLab repositories you would like to clone and click “Clone”.

  4. Enter your name in the filter to quickly access your repository and select the arrow beside the repository you would like to locally clone.

  5. Click location and select where you would like this repository to exist and click clone at the bottom right of the window and don’t forget to subsequently type the name of the new repository folder at the end of this path (it is a bit buggy and not intuitive). It is advisable you only place whatever you are ok with potentially being seen by others in this folder, keep data stored outside this folder.

1.3.2 Amending Code/Files

  1. You can then navigate yourself where ever you decided to place the repository above and make changes to your code/documents. Once you made a change it will be observable in Sourcetree.

  2. Navigate to Sourcetree and click the repository you made changes to when you want to update it on GitLab.

  3. Click the branch under “BRANCHES” option in the menu on the left-hand side where the change is located. You will see a list of changes, starting with the initial commit, in chronological order with the most recent at the top.

  4. Select the “Uncommitted changes” option in the main panel and review the changes waiting to be committed in the bottom large panel.

  5. Once you are ok with the changes made, click the “Commit” icon on the top left-hand side.

  6. You then have the option of commenting on the commit at the bottom panel. It is recommended you do so to keep track of what is being done and why.

  7. Here you can push changes to the origin/main branch if you select the box on the bottom-left prior to selecting Commit and immediately send the updated code/document to GitLab. You may not want to do this if there is a lot of changes to be made in a given repository and instead of spamming pushes to GitLab you can commit to many and push everything at once.

  8. If you did not select push in the option prior to committing then you will notice a number icon on the “Push” icon on the top left. You now want to select this icon.

 

Work by Nicole Gladish

ngladish@stanford.edu