Commit Changes to GitHub

It takes a lot of time to master git. Managing source repositories is one part technical knowledge and one part technical leadership and both are difficult to master. I found that the best way to get started is by getting a lot of practice with the most basic parts of the process, committing code to a personal repository (where there are no other people to manage). In this lab you’ll edit a file and commit your change to the repository you created in the Setup GitHub lab.

Step 1: Update README.md

Edit the README.md file that’s a part of the class repository and add a line at the bottom with your name like the example below:

Author: Your Name Here

Make sure you save the file after the change.

Step 2: See the Status of Your Repo

The git status command shows you what’s changed in your repo. Run it and you should see something like this:

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

Notice that README.md has been modified.

Step 3: Examine the Changes

The git diff command shows you what has changed inside the files. Execute it and you should see the line you added to README.md

$ git diff
diff --git a/README.md b/README.md
index dbe1396..ffdc2e5 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
 # Cabrillo CIS-91 Public Course Files 
 
 This is a work in progress.
+
+Author: Mike Matera

A line with a + is an addition and a line with a - is a deletion. Your result will look a bit different than mine because I’m working with a very early copy of README.md.

Step 4: Stage Your Change

When you’re ready to commit a change the first thing to do is stage the change. Staging tells git which of the changes you would like to commit. As you work you will find that you frequently don’t want all of the changes in your repo to go into the commit. In this step you stage the README.md file.

$ git add README.md

Now let’s see that it’s staged:

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

Step 5: Commit Your Change

Now that the change is staged. It’s ready to commit. Every commit has a message that tells you what the commit changed. The message is intended to be a reminder to you when you look at your code later. Picking the right message is more art than science. I’ve picked the first one for you, later you’ll choose your own.

$ git commit -m "Personalized README.md"
[main 97800bd] Personalized README.md
 1 file changed, 2 insertions(+)

We’re not done yet!

Step 6: Push Your Change to GitHub

The last step is to push the changes to GitHub. This keeps your code safe in the case anything should happen to your computer or cloud shell.

$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 357 bytes | 357.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:mike-matera/cis-91.git
  f1dece2..97800bd  main -> main

Check your github account! You should see a banner telling you that there are new changes.

Turn In

A screenshot of your change on GitHub