Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active September 27, 2021 05:04
Show Gist options
  • Save acidtone/83839837bed6c5dadd7357a0b6170947 to your computer and use it in GitHub Desktop.
Save acidtone/83839837bed6c5dadd7357a0b6170947 to your computer and use it in GitHub Desktop.
Git Activity: Add an untracked file to a local repo

Git Activity: Add an untracked file to a local repo

  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. Create/move an index.html file inside your cloned repo.

  2. Check your repo status.

    $ git status
    

    You should see index.html as an untracked file:

    On branch main
    Your branch is up to date with 'origin/main'.
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
      index.html
    
    nothing added to commit but untracked files present (use "git add" to track)
    
  3. Add index.html to track the file with Git (you'll be using add a lot in your dev life):

    $ git add index.html
    
    • You need to explicitly add changes before they can be committed later, because Git.
  4. Check your repo status (you can never check your repo status enough).

    $ git status
    

    You should see index.html as a new file to be committed:

    On branch main
    Your branch is up to date with 'origin/main'.
    
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
      new file:   index.html
    
  5. Commit your new file:

    $ git commit -m "added index.html"
    

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment