Git Basic Operations
Git's job is to create and save snapshots of your project and compare them with subsequent snapshots.
This chapter will introduce commands related to creating and submitting snapshots of your project.
The commonly used Git commands are the following 6: git clone, git push, git add, git commit, git checkout, git pull. We will discuss them in detail later.
Explanation:
- workspace: Working Directory
- staging area: Staging Area/Cache
- local repository: Repository or Local Repository
- remote repository: Remote Repository
A simple sequence of operations:
$ git init
$ git add .
$ git commit
- git init - Initialize a repository.
- git add . - Add files to the staging area.
- git commit - Add the contents of the staging area to the repository.
Repository Creation Commands
The table below lists Git commands for creating repositories:
Command | Description |
---|---|
git init | Initialize a repository |
git clone | Copy a remote repository, i.e., download a project. |
Submission and Modification
Git's job is to create and save snapshots of your project and compare them with subsequent snapshots.
The table below lists commands related to creating and submitting snapshots of your project:
Command | Description |
---|---|
git add | Add files to the staging area |
git status | Check the current status of the repository, display files that have been changed. |
git diff | Compare differences in files, i.e., the difference between the staging area and the working directory. |
git commit | Submit the staging area to the local repository. |
git reset | Revert to a previous version. |
git rm | Remove files from the staging area and the working directory. |
git mv | Move or rename files in the working directory. |
Commit Log
Command | Description |
---|---|
git log | View historical commit records |
git blame <file> | View the historical modification records of a specified file in list form |
Remote Operations
Command | Description |
---|---|
git remote | Remote repository operations |
git fetch | Fetch a repository from a remote |
git pull | Download remote code and merge |
git push | Upload remote code and merge |