Git Key Commands and GitHub Key Features
This page summarizes the key Git commands and key GitHub features covered in this course. You can use this page as a cheat sheet.
Chapter 2. Git & GitHub Initial Settings
$ git config: a command used when you register (or change) key user settings in the Git system. For example, you can do the following with this command
- Register your username and email address
- Register a text editor
- Check configured settings
- Clear configured settings
Chapter 3. Git & GitHub Project Setup
$ git init: a command used for initiating a Git project by creating a new Local Repository in the current directory.
$ git clone: a command used to create a link to a Remote Repository and bring the project directory from the Remote Repository with commit histories to your local computer. This command is used only the first time you bring the project directory to your local computer. The git clone
command establishes a connection between the Remote Repository and your local computer by registering on your computer the URL that defines the location of the Remote Repository. Once the connection is established, you can Pull or Fetch the Remote Repository.
Fork: a feature provided by GitHub and used to create a replica of a Remote Repository on GitHub. After implementing Fork, the replicated repository will be separated from the original repository. You can modify codes in the replicated repository on your own without permission from the owners of the original repository (within the software license agreement, if any). Fork is not a git command. It is executed on the GitHub website. Go to the GitHub site and find the repository which you want to create a replica of. There is a Fork button on the Remote Repository page. Press the Fork button to implement Fork.
Chapter 4. Edit & Commit
$ git add: with this command, you can add files to the Staging Area (INDEX), where you can prepare and check files before registering in your Local Repository.
$ git status: with this command, you can see the status of the Working Tree (working directory) and the Staging Area (INDEX). This status lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.
$ git commit: with this command, you can register files in your Local Repository. Once the files are registered, you can retrieve the saved version of the set of files at any time.
$ git log: with this command, you can check the information on the commit history of the repository
$ git diff: with this command, you can check differences between the Working Tree, Staging Area (INDEX), and commit histories.
$ git restore: with this command, you can bring your Working Tree back to the latest commit or a specific commit. This command is useful when you want to clear your edits and go back to a cleaner version.
$ git rm: with this command, you can delete files or directories under the Working Tree and the Staging Area (INDEX). When you want to reflect the deleted status as a formal version, you need to create another commit.
$ git reset: with this command, you can reset the Staging Area (INDEX) or change commit histories with or without changing the contents of your local files.
Chapter 5. Work With Branches
$ git branch: this command is a multi-use command. For example, it is used for creating a new branch, checking branch status, and deleting an unused branch.
$ git checkout: with this command, you can switch your current branch to a selected branch.
$ git switch: with this command, you can get the same result as that of git checkout
. It is a command newly introduced as a substitute for the git checkout
command.
$ git merge: with this command, you can merge branches. The merge operation can be done through a Remote Repository on the GitHub website.
$ git rebase: with this command, you can reapply commits on top of another base branch. This command is useful when you want to streamline commits that diverged into multiple branches. The rebase operation can also be done through a Remote Repository on the GitHub website. It is an option of the merge feature of GitHub.
$ git stash: with this command, you can separately manage WIP (Work In Progress) codes. When you want to switch the current branch in the middle of editing the Working Tree, the edits can prevent you from switching the current branch. In that case, this command is useful. The stashed lines of code are parked somewhere temporarily.
Chapter 6. Remote Collaboration
$ git remote: this command is a multi-use command relating to managing a Remote Repository. For example, with the git remote add
command, you can establish a link between a Remote Repository and a Local Repository. The git remote -v
command shows the status of the link.
$ git push: with this command, you can upload project directories and files along with commit histories for a specified branch from your computer to a Remote Repository
$ git pull: with this command, you can download project directories and files along with commit histories for a specified branch from a Remote Repository. This command also merges the downloaded branch with an existing branch under the Local Repository.
$ git fetch: with this command, you can obtain the latest Remote Repository information and store it on your local computer. This command doesn't enforce merging branches in the Local Repository. If you want to update the Local Repository, you need to run the git merge
or git checkout
command.
Pull request: this feature is used to ask a reviewer to review your edits. It is especially useful when you want to ask the reviewer to merge your branch (a topic branch) with the main branch (e.g., master branch).
Merge: this feature gives similar functionality as the git merge
command and the git rebase
command. You can execute merge or rebase operations on the GitHub website. There are three merge approaches. 1) Create a merge commit, 2) Squash and merge, 3) Rebase and merge.