modules

Using Git Locally

Now let’s learn how to use Git locally from our computer. While there are GUIs (graphical user interfaces) for Git on your computer like GitHub Desktop, we’re going to use the command line to learn Git. That’s because this is a key transferrable skill that applies to any kind of coding.

Some Vocabulary

Within a Repository you have

Components of a Git Repository

  1. The working directory
    • git init creates a git repo inside current working directory. This means that this command can turn a regular folder into a git repository by generating a hidden .git folder that starts to keep track of changes.
    • git clone takes a git repo from somewhere else and makes a copy of that repo into your current working directory. We will frequently be cloning repos from GitHub.
  2. The staging area
    • git add . adds changes from the working directory to the staging area
    • git add <filename> adds changes to filenames specified from the working directory to the staging area
  3. The commit
    • git commit -m "commit message" adds changes in staging area to the repository
    • git log shows

Protip: Run git status after each command in the beginning because it allows you to visualize what just happaned.

Pushing to GitHub

Key Terms

  1. In order to show your remotes, you can run git remote -v show. The default remote is named “origin”
  2. In order to push, you run git push. By default this will push from the branch you are on to a remote branch with the same name. (If you’d like to specify a branch, you can do that. The full formulation of this command is git push <remote> <branch>. So, for example you might say git push origin main to push to the “main” branch of the “origin” remote.)

❇️ Example: simple-website

Let’s give it a try! We’re going to clone a repository for a simple website from GitHub down to our computer where we can work with it locally. We will make some edits to the code, commit those changes and then push the changes back up to the remote repository in GitHub.

https://github.com/code4policy/simple-website