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.
.git
folder) that stores the changes to those files.Within a Repository you have
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.git add .
adds changes from the working directory to the staging areagit add <filename>
adds changes to filenames specified from the working directory to the staging areagit commit -m "commit message"
adds changes in staging area to the repositorygit log
showsProtip: Run git status
after each command in the beginning because it allows you to visualize what just happaned.
git remote -v show
. The default remote is named “origin”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.)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