Lab 1: Git and Source Control

Topics: Source Control, BitBucket, Git basics

Group work: Group work is allowed for the labs, but each person must do their own coding and each person must turn in an assignment. Copying other peoples' code / code files is not allowed. Copied assignments will receive 0% for everybody involved.


 

About

Source Control is a necessary tool for developers and all programmers should have some level of fluency with it. During this semester, you will be storing your projects in a repository.


Requirements

Use the documentation provided (class lecture, external reading, asking questions) to complete the following:


 

1. Download Git

If you're on a school computer, Git is already installed. If not, go to https://git-scm.com/downloads and install the version for your operating system.

The Git installer will install Git Bash and Git GUI; you can use either of these for this lab but I'm giving the Bash (command-line) instructions.


 

2. Create a BitBucket account

Go to BitBucket.org and create an account.


 

3. Create a fork of the cs250-student-repository

I've created a student repository here: cs250-student-repo">cs250-student-repo.

This creates starter files for some of the labs and a simple README file.

Click on the "+" button on the left bar, then click Fork this repository to make a copy to your account.

Make sure to check This is a private repository, then click Fork repository.


 

4. Open Git and navigate to a project directory

There are several ways you can access git after installing it.

  1. Git Bash/GUI Start Menu: You can open Git Bash or Git GUI from here.
  2. Git Bash from current directory: On the computer, you can right-click in your working directory and select "Open Git Bash" here.
  3. Command Prompt or Power Shell from current directory: If you hold shift and right-click in your working directory, a "Open Command Prompt" or "Open Power Shell" option will be available. You can use command-line Git commands from here.
The school computers may not give you (2) available, but you should be able to use (1) or (3).

To view the current directory where Git Bash is open in, you can use the pwd command:

$ pwd
/home/rach/temp

To view what files/folders are in the current directory, use the ls command:

$ ls
discrete-structures                       edu-moosader-homepage
cs134-programming-fundamentals            other-teachers-resources
cs200-concepts-of-progamming-algorithms   page-content
cs-211-001-82502-dot-201808-export.imscc  server.sh
cs250-data-structures                     cs250-student-repo

To move back one folder, you can use the cd .. command. To enter a folder, use the cd FOLDERNAME command.


 

5. Clone your CS 250 repository on to your local machine.

Click on the Clone button and copy the git clone command it gives you.

(Windows) Open Git Bash, the command prompt, or PowerShell on your machine's desktop. (Open command prompt: SHIFT+RIGHT-CLICK)

(Linux/Mac) Open the Terminal and navigate to where you want to store your projects.

Paste the git clone command and hit ENTER.

Sign in using the popup that shows up. If that doesn't work, run the command again and "cancel" out of the popup and sign in from the terminal.

Now the cs250-student-repo will be on your computer.

In the terminal, make sure you're in the cs250-student-repo directory (Use cd PATHNAME] to enter the folder).

Keep the terminal open for now.

$ git clone https://rejcx@bitbucket.org/rachelsteaching/cs250-student-repo.git
Cloning into 'cs250-student-repo'...
remote: Counting objects: 183, done.
remote: Compressing objects: 100% (171/171), done.
remote: Total 183 (delta 57), reused 0 (delta 0)
Receiving objects: 100% (183/183), 2.34 MiB | 2.20 MiB/s, done.
Resolving deltas: 100% (57/57), done.
Checking connectivity... done.

 

5. Edit the README.txt file

Navigate to the directory where your repository is and open up README.txt in a text editor. Change some text in the file and save it.


 

6. View the repository Status

Type git status in the terminal and hit enter. It will tell you what files have changed and are awaiting commit.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

	modified:   README.txt

no changes added to commit (use "git add" and/or "git commit -a")
        

 

8. Add the change to a snapshot.

Type git add README.txt in the terminal and hit enter.


 

9. Commit a snapshot.

Type git commit -m "asdf" in the terminal, replacing asdf with a description of what you have changed.

Now your changeset is saved locally, but not on the server.


 

10. Push the changes to the server.

Type git push in the terminal to push your changes to the server.

Go to the web-view of your repository to ensure that your changes show up now.


 

Turn in

Take a screenshot of your repository front page and upload it as the assignment file.

You should upload your future labs, projects, and notes to this repository.

We will make the repository public at the end of the semester.