Skip to main content

Section D.2 Git Commands

This section contains the most common commands used at the command line to interact with Git. To see these commands in the context of a workflow, see Section 4.5 and Section 6.5.
git clone
Used to copy (“clone”) a repository from GitHub to a local source. Also requires an HTTPS link copied from GitHub.
git branch
Used to create a new branch in the background. Also requires the name of the branch you wish to create.
git switch
Used to change branches. Also requires the branch name you wish to change to.
Can be used as git switch -c with a branch name to create and change to a branch automatically (i.e., git branch is not required).
git status
Used to check up on the state of Git operations. Can be entered at any time in the Git process.
git add
Used to stage files to prepare them for committing and attaching a commit message. Requires either a . (to add all modified/new files) or a number of file and folder names.
git commit -m
Used to commit files and to attach a commit message (surrounded in quotes). Automatically attaches this message to the files staged using git add and makes a stamp in the respective file timelines.
git push
Used to push changes from a local source to GitHub. Requires the remote repository (origin or upstream) and the branch name you wish to send changes to.
git pull
Used to pull in changes from GitHub to a local repository. Requires the remote repository (origin or upstream) and the branch name you wish to pull changes from.