Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

(CSCE 1102)

Fundamentals of Computing II Lab

Session 01 - Lab Practice


Git and GitHub

Installation and Sign Up on GitHub

• If you do not install Git please follow the instructions uploaded on Blackboard.
• If you do not have an account on GitHub please sign up here: https://github.com/

Part 1: Creating and Manipulating the Local Git Repository

1. Create a new folder (directory) on Desktop called: “git-exercise”.


Inside this folder, add a text file called: “Sample.txt” and write your name in the file.

2. Save and close the file.


Note: the following steps are applied using Git bash in windows if you are a mac user write
the same commands in the terminal.

3. Open Git Bash.


Note: In the subsequent screenshots, the $ is not a part of the command, so write the command
written after the $ sign.

4. If this is your first-time using Git, you need to set your user.name and user.email in
configuration using the following commands.
git config --global user.name “YourName”
git config --global user.email “YourEmail”

|Page1
(CSCE 1102)
Fundamentals of Computing II Lab

5. Go to the ‘git-exercise’ directory using the ‘cd’ command.


Note: you need to put the path between quotes ‘ ’ because it may contain spaces.

6. Initialize a Git repository inside your working directory.

Note: you can notice that the word ‘(main)’ will be written after using the git init command
indicating that you are inside a Git rep ository now.
Note: you will find a hidden folder called “.git” created automatically inside your working
directory after using the git init command.

7. Add all the files using the git add command.


Note: ‘.’ Add all the files in the directory.

8. Commit the changes into the local Git repo using the git commit command.
Note: you should choose a descriptive message to write after the ‘-m’ option describing the
changes made in this commit.

9. View the status of the repo using the git status command.
Note: the message ‘nothing to commit, working tree clean’ indicates that all the changes
made in your working directory are already committed to the local repo.

|Page2
(CSCE 1102)
Fundamentals of Computing II Lab

10. Edit the “Sample.txt” file and add your ID then save and close it.

11. View the status of the repo.


Note: the message ‘Changes not staged for commit’ means that you changed “Sample.txt” in
the working directory, but you haven’t made git add and git commit yet.

12. Git add all files.

13. View the status of the repo.


Note: the message ‘Changes to be committed’ means that “Sample.txt” added using git add
but still needs to be committed.

14. Git commit with a descriptive message and view the status.

15. Use the git log command to view the list of all commits.

Note: You can use the ‘--oneline’ option to display each commit in one line.

|Page3
(CSCE 1102)
Fundamentals of Computing II Lab

Part 2: Creating and Connecting with a Remote Repository on GitHub

1. Sign in with your account on GitHub.

2. Create new repository on GitHub.

3. Choose the repository name, select add readme file, and press “Create Repository”.

|Page4
(CSCE 1102)
Fundamentals of Computing II Lab

4. In GitHub, on the “Code” tab press on Code to get the URL of the remote repo.

5. In “HTTPS” copy the link.

6. Create a new empty folder on desktop called “git-cloned-repo”.


7. In your Git Bash, cd to this folder.

8. Use the git clone command to take a copy of the remote repo to the “git-cloned-repo”
folder. Note that the URL entered after the git clone is the URL of the remote repo.

Note: use the link that you copied from GitHub.

After the git clone, you will find the “git-cloned-repo” folder now contains the folder of the
remote repo.

9. Go inside the cloned folder using the cd command. For example, here the repo name is
“git-learning”.

|Page5
(CSCE 1102)
Fundamentals of Computing II Lab

10. In the cloned folder, create a “codeSample.cpp” file and edit it by adding an empty main
function.
Note: if you have a problem in creating a “.cpp” file you can download it from blackboard and
move it to your cloned folder.

Note: for simplicity, to view the content of the code


file if you want you can open it using any text editor.
(In this document we used Notepad++ software)

11. Git add and commit.

12. Git push your changes to the remote repo using the git push command.

13. Refresh the repository on GitHub and you will find the “codeSample.cpp” file on GitHub

14. Click on the file and edit it by clicking on the edit icon.

15. Add the following line in the file and then click on commit changes with a descriptive
message.

|Page6
(CSCE 1102)
Fundamentals of Computing II Lab

16. In Git Bash, use the git pull command to download the changes from the remote repo.

Note: if you open your cloned folder you will find the “codeSomple.cpp” edited.

Good Luck,
Your TA. Walaa Alkady

|Page7

You might also like