The most essential Git commands you must know

Tags: , ,

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.

git file change diagram

The four stages of a file in git

git diagram

  1. Create a Repository

    Create a new local repository from scratch

    Download from an existing repository

  2. Check your repository

    List the files that have not been committed 

    Show the changes to files not staged

    Show full change history

    Show more detailed change history

    show the changes between two commits ids

  3. Git Branches

    List all local branches

    List all local and remote branches

    create a new branch

    Switch to a branch

    create a new branch using an old branch and switch to the new branch

    delete a local branch

    delete a remote branch

    tag a branch

    merge branch_a to branch_b

  4. Add files to repository and do commit

    Add a single file to index, ready for commit

    Add all the updated tracked files to index, ready for commit

    Add all the files to index, ready for commit

    Commit the staging files

    Unstage files, keep the file changes

    Revert everything to the last commit

  5. Word with remote repository

    Upload your local branch to your remote branch

    Get all the remote forked branches to local

    List the current configured remote repository for your fork.

    Specify a new remote upstream repository that will be synced with the fork.git

    Verify the new upstream repository you’ve specified for your fork.

    Build a new branch using upstream master 

    Rebase your local branch with the upstream master branch

  6. Reference:

    https://help.github.com/articles/configuring-a-remote-for-a-fork/

    http://zeroturnaround.com/rebellabs/git-commands-and-best-practices-cheat-sheet/