
Git is the most widely used modern version control system. When you learn git, you may encounter issues to master all the git commands. In this tutorial, we list the essential git commands. After master these commands, you can use git to accomplish most of the version control tasks.
The following two diagrams show how git manages your files.
The four stages of a file in git
-
Create a Repository
Create a new local repository from scratch123456git init [my_project]orcd my_projectgit initDownload from an existing repository
1git clone remote_reposity_url_on_github -
Check your repository
List the files that have not been committed1git statusShow the changes to files not staged
1git diffShow full change history
1git logShow more detailed change history
1git reflogshow the changes between two commits ids
1git diff commit_id1 commit_id2 -
Git Branches
List all local branches1git branchList all local and remote branches
1git branch -avcreate a new branch
1git branch my_branch_nameSwitch to a branch
1git checkout my_branch_namecreate a new branch using an old branch and switch to the new branch
1234567git checkout old_branch_namegit checkout -b new_branch_nameorgit checkout old_branch_namegit branch new_branch_namegit checkout new_branch_namedelete a local branch
1git branch -d branch_namedelete a remote branch
123git push origin :{the_remote_branch}orgit push origin --delete the_remote_branchtag a branch
1git tag my_tagmerge branch_a to branch_b
12git checkout branch_bgit merge branch_a -
Add files to repository and do commit
Add a single file to index,