Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active September 27, 2021 05:15
Show Gist options
  • Save acidtone/47cb2768acdd42e84ba2ef8229427983 to your computer and use it in GitHub Desktop.
Save acidtone/47cb2768acdd42e84ba2ef8229427983 to your computer and use it in GitHub Desktop.
Git Activity: Commit changes to a tracked file

Git Activity: Commit changes to a tracked file

  1. Create a GitHub repository
  2. Clone a GitHub repository
  3. Add an empty webpage to a local repo
  4. Commit changes to index.html.
  5. push changes to GitHub.
  6. Deploy your GitHub repo to GitHub Pages.

Pre-requisites

  • You see nothing to commit, working tree clean when you check your repo status:

    $ git status
    

Instructions

  1. Using your code editor (VS Code, for example), make a change to index.html (or some other file) and save the file.

    • For example: update the <title> of index.html.
  2. Check the status of your repo:

    $ git status
    

    Git notices you've changed a file.

    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:   index.html
    
    no changes added to commit (use "git add" and/or "git commit -a")
    
  3. Notice Git is telling us what to do next (add changes with add):

    $ git add index.html
    
    • You need to explicitly add changes before they can be committed later, because Git.
  4. Let's check our status again:

    $ git status
    

    Our changes are now "staged" (i.e. ready to be committed):

    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
        modified:   index.html
    
  5. Commit your staged changes:

    $ git commit -m "updated page title"
    

    Git will save your changes as a snapshot of your project.

    [main 169a1b0] added index.html
     1 file changed, 11 insertions(+)
     create mode 100644 index.html
    
    • Warning: Commit messages are mandatory. If you omit -m "some commit message", your terminal will open vim or some other command line text editor. Worst case: close your terminal window and open another one.
  6. Confirm the status of your repo:

    $ git status
    

    You should see nothing to commit, working tree clean.

Next Steps

  1. Make more changes! Repeat the above steps until they become comfortable. For example:
    • Add/update a <p> in the <body> of index.html;
    • Add/edit embedded CSS in the <head> of index.html using <style>
    • Link an external CSS file in the <head> of index.html using </link>.
  2. When you're ready, push your changes to GitHub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment