Git Cheat Sheet: For Every Beginner and Developer

Git Cheat Sheet: For Every Beginner and Developer
Git Cheat Sheet: For Every Beginner and Developer

Introduction to GitHub

Before we jump on to reading the Git Cheat Sheet, let us take a quick relook at the platform. GitHub is a Microsoft developed programme that provides a platform for collaborative work or group projects. Generally in the software development community around five to ten people work on the same project.

An application that has got 10 screens, has around thirty to fifty files of codes, which is impossible to share through e-mail or other sharing resources.

With the help of GitHub, developers can easily upload their code to their GitHub account and share the link with their peers, so that the peers may review their code or append some modules to their code.


Git Cheat Sheet: For Every Beginner & Developer

It is very difficult to have all the commands and their syntax at your fingertips. In the case of highly skilled developers, it might be possible but for beginners, it is an effort-taking task. We have prepared a complete Git Cheat Sheet for every beginner and developer:

1. Creating a repository: Git Cheat Sheet

  • Clone an existing repository.
    • Syntax: $ git clone
  • Create an empty repository.
    • Syntax: $ git init

2. Adding Local Changes: Git Cheat Sheet

  • Changed files in the working directory
    • Syntax: $ git status
  • Changes to track files
    • Syntax: $ git diff
  • Adding all the current changes to the next commit
    • Syntax: $ git add.
  • Adding some changes to the next commit
    • Syntax: $ git add -p
  • Commit all local changes in tracked files
    • Syntax: $ git commit -a
  • Commit previously staged changes
    • Syntax: $ git commit
  • Change the last commit
    • Syntax: $ git commit -amend

3. Commit History: Git Cheat Sheet

  • View all commits, starting from the latest one
    • Syntax: $ git log
  • Show all the changes made in a file in a specific period
    • Syntax: $ git log-p
  • Changes made by a person in a with timing
    • Syntax: $ git blame

4. Branches and Tags: Git Cheat Sheet

  • List all existing branches
    • Syntax: $ git branch -av
  • Switch master branch
    • Syntax: $ git checkout
  • Create a new branch based on the master branch
    • Syntax: $ git branch
  • Create a new tracking branch with reference to the current branch
    • Syntax: $ git checkout –track
  • Deleting the current branch
    • Syntax: $ git branch -d
  • Adding a tag to the current commit
    • Syntax: $ git tag

5. Updating and Publishing: Git Cheat Sheet

  • List all currently configured remotes
    • Syntax: $ git remote -v
  • Show information about a remote
    • Syntax: $ git remote show
  • Add new remote repository, named
    • Syntax : $ git remote add
  • Download all changes from remote without merging with master
    • Syntax: $ git fetch
  • Downloading changes and merging directly into the master
    • Syntax: $ git pull
  • Publishing local changes on a remote
    • Syntax: $ git push
  • Deleting a branch on the remote
    • Syntax: $ git branch -dr
  • Publishing your tags
    • Syntax: $ git push –tags

6. Merge & Rebase: Git Cheat Sheet

blog banner 1
  • Merge into the current master
    • Syntax : $ git merge
  • Rebase your current master into
    • Syntax: $ git rebase
  • Aborting a rebase
    • Syntax: $ git rebase –abort
  • Continuing a rebase after post-conflict resolution
    • Syntax: $ git rebase –continue
  • Using your configured merged tool to solve conflicts
    • Syntax: $ git mergetool
  • Manually resolving conflicts with the help of the editor, and marking the file as resolved
    • Syntax: $ git add
    • Syntax: $ git rm

7. Undo: Git Cheat Sheet

  • Discard all changes in the working directory
    • Syntax: $ git reset –hard master
  • Discarding local changes in a specific file
    • Syntax: $ git checkout master
  • Reverting a commit
    • Syntax: $ git revert
  • Resetting the master pointer to any previous commit and discarding all the changes made since then
    • Syntax: $ git reset –hard
  • Preserving all changes as unstaged
    • Syntax: $ git reset
  • Preserving uncommitted local changes
    • Syntax: $ git reset –keep

8. Help and documentation: Git Cheat Sheet

  • Getting help on the command line
    • Syntax: $ git help

Frequently Asked Questions

What is git command?

GitHub comes with one lined Git commands to move (push) your code from a local repository to a remote repository or to grab (pull) someone’s collective code from a remote repository. Git has a “remote” command to deal with remote repositories. All the operations such as checking out into a new branch, creating a new branch, add codes, making commits. Everything is carried out with the help of these Git commands.

What are the basic Git commands?

The most popularly used Git commands are:
git init
git add
git push
git pull
git clone
git commit
git status
git config
git branch
git checkout
git merge

What is GitHub and what are git commands?

GitHub is a Microsoft developed programme that provides a platform for collaborative work or group projects. It comes with a wide set of commands for carrying out operations on the local and remote repositories, so that beginners and developers can add, delete, merge, push, push, clone source code from target repositories.

Where do I type git commands?

You can use the command-line interface of GitHub, ‘git bash’ either through the start menu or by right clicking in the folder. Press the ‘Start’ button in Windows, type ‘cmd’ in the search field on the bottom of the menu. The command line console window will open. Type git –version , it will show something like ‘git version 1.8. This confirms that Git is successfully installed in the system.

What is git rebase?

Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is highly useful for beginners and developers and efficiently visualised in the context of a feature branching workflow.

Rebase compresses all the changes into a single “patch.” Post-this, it integrates the patch onto a target branch. In contrast to merging, rebasing eliminates the history because it transfers the completed work from one branch to another.

Key Takeaway

Nowadays, during the hiring process, the employee asks for the GitHub profile of the developer so that he may analyse his skills through his previous project works and the clarity of his codes. Beginners can also refer to the repositories created by coders to see the functions that are available.

We can regularly update the repositories created by us. GitHub is absolutely free software. It is highly used by software developers across the globe.

Therefore, you must go through the Cheat Sheet thoroughly and keep it handy with you so that you are never stuck when you are collaborating.

By Vanshika Singolia