Git Commands - A Cheat Sheet For Popular Version Control System

Git Commands Cheat Sheet

No Git command cheat sheet would be complete without a section on the Git vocabulary, so we’ve included one to help you get to grips with how Git works and how the commands are run on various entities. In fact, let’s begin there:

Git Commands Cheat Sheet – Vocabulary

#

Git Command

What it Does

1Bare RepositoryRepository that doesn’t have a working directory.
2BranchAn active area of development in Git. The newest commit displays the end of the branch.
3BlameRefers to the most recent alteration to every line in the file. Shows Author, Revision, and Time.
4CheckoutThis is talking about the process whereby a particular commit is chosen from the repository and the condition of the file associated with it and the directory tree are reproduced in the working directory.
5CommitRecord of a moment in Git history containing details of a changeset.
6DiffThe difference in changes between saved changes or two Commits.
7Detached HeadThe state in which a specific commit is checked out rather than a branch.
8FetchRetrieves the most recent changes in the branch and the local or remote repositories.
9ForkWhen you Fork the repository, you can add Commits and add Pull Requests.
10HashA unique SHA1 code for each Commit
11HeadThe name of the Commit at the end of a Branch
12IndexA group of files that hold state information.
13MergeIncludes changes from named commits (from when their histories split from the current branch) into the current branch.
14MasterGit’s default development Branch
15OriginThis is the default Upstream Repository
16Pull RequestSuggests changes into the Master Branch
17PushPushes new changes once they’ve been committed
18RepositoryA group of Commits, Branches and Tags to identify Commits.
19Working TreeThe directory of files that you are currently working on

Git Commands Cheat Sheet – Configuration

#

Git Command

Description

1git config –global user.nameSets the username to be used for every action
2git config –global user.emailSets the email to be used for every action.
3git config –global alias.Generates a shortcut for the Git command.
4git config –system core.editorSets the text editor for all command actions.
5git config –global –editOpens global configuration file in the text editor to enable manual editing.
6git config –global color.ui autoTurns on colour for command line outputs as a visual aid.

Git Cheat Sheet – Set Up a Git Repository

#

Git Command

Description

1git initInitializes an empty Git repository in the current project.
2git clone (Repo URL)Clones the repository from GitHub to the project folder.
3git clone (Repo URL) (Folder)Clones the repository to a specific folder.
4git remote add origin

https://github.com/username/(repo_name).git

Creates a remote repository that points to your current GitHub repository.
5git remoteDisplays the name of remote repositories.
6git remote -vDisplays the name and URL of remote repositories.
7git remote rm (remote repo name)Gets rid of a remote repository.
8git remote set-url origin (git URL)Changes a repository URL.
9git fetchObtains the most recent changes from the origin but doesn’t merge them.
10git pullObtains the most recent changes from the origin and merges them.

Git Cheat Sheet – Local File Changes

#

Git Command

Description

1git add (file name)Adds current file changes to staging.
2git add .Adds changes for the whole directory to staging but without deleting files.
3git add -AAdds every new, modified, and deleted file to staging.
4git rm (file_name)Stops tracking a file and gets rid it.
5git rm –cached (file_name)Stops tracking the current file.
6git mv (file_name) (new_file_name)Alters the filename and gets it ready for Commit.
7git checkout <deleted file name>Undeletes a file and gets it ready for Commit
8git statusDisplays the status of modified files.
9git ls-files –other –ignored –exclude-standardDisplays a list of each ignored file.
10git diffDisplays staged changes in the working directory and index.
11git diff –stagedDisplays differences in files between the most recent version and staging.
12git diff (file_name)Displays changes between a single file and the most recent Commit.

Git Commands Cheat Sheet – Declare Commits

#

Git Command

Description

1git commit -m “(message)”Saves changes along with a custom message.
2git commit -am “(message)”Adds all changes to staging and saves them with a custom message.
3git checkoutSwitches to the provided Commit.
4git showOutputs content changes and metadata for a particular Commit.
5git reset –hardRolls back all history and changes for a specific Commit.
6git reset –hard HeadRolls back all local changes in the working directory.
7git logDisplays change history.
8git log -pDisplays the full page for each Commit.
9git log -onelineDisplays a list of Commits and a simple message.
10git log –follow (file_name)Shows the history of the present file.
11git blame (file_name)Displays all changes and the user’s name.
12git stashDoes an Interim save of all tracked files that have been modified.
13git stash popRestores files that were stashed most recently.
14git stash listDisplays all stash changesets.
15git stash applyApplies the most recent stashed contents.
16git stash dropGets rid of the most recently stashed files
17git stash apply (stash id)Re-applies content of a particular stash by ID.
18git stash drop (stash_id)Drops particular stash content by ID.
19git pushPushes changes to the Origin.
16git push origin (branch_name)Pushes branch to the Origin.
17Git push -f origin (branch_name)Force pushes the changes to the Origin.
18git tag (tag_name)Specifies a tag for a version.
19git pushPushes changes to the Origin.

Git Commands Cheat Sheet – Branching

#

Git Command

Description

1git branchDisplays a list of every branch.
2git branchMakes a new branch.
3git branch -mChanges the name of a branch.
4git branch -aLists both local and remote branches.
5git checkout -bCreates a branch and switches to it.
6git checkoutChanges to a particular branch.
7git checkout -b origin/Puts a remote branch from the origin in the local directory.
8git branch -dDeletes the specified branch.
9git mergeMerges the current branch with the master (first checkout to master)
10git rebaseIntegrates changes from one branch into another by rewriting the commit history to produce a linear succession of commits.
11git rebaseRebases the current branch onto the base, which can be a Commit ID or a branch name.
12git fetch remoteFetches the specified branch from the repository.
13git diff ..Shows the differences between two branches.
14git pull –rebaseFetches the remote copy of the current branch and rebases it into the local copy.
15git push –allPushes all the local branches to the specified remote repository.

Plesk and Git Support

Plesk lets you integrate with Git, because for most web developers it’s their go-to code management system. Git makes it easy to handle initial publishing and subsequent updates by deploying your website from repositories to a public directory.

Here’s how to get started with Git:

  1. Install the Git extension in Plesk.
  2. Create a domain in Plesk with a service plan that lets you give management permission to Git.

There are two types of repositories that you can add in Plesk, and you’ll choose the one that best fits your use case:

  1. Keep it local with a repository on your own machine. In this scenario, you send the changes to Plesk from your local repository, and then Plesk deploys the changes to your website.
  2. Use Git hosting remotely. You might want to do it this way if you’re already using a remote repository in BitBucket (bitbucket.org) or GitHub (github.com). You forward your changes to the remote repository, then Plesk gets them from it and deploys them to your website.

When you’ve got Git repositories enabled in your domain, you’ll be able to see a list of the ones that have been created on its page. For each one you’ll see the name, the current branch and the deployment path. The Deploy button (look it for it near the repository name) lets you deploy the files from a repository (if it’s been set up for manual deployment) and the Pull Updates button lets you get the changes from the remote repository.

Conclusion

It’s much easier to work on a complex project when you have a list of Git commands in front of you, so we hope that this Git command cheat sheet proves to be useful.

How useful was this post?

Click on a heart to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Oh no, sorry about that!

Let us know how we can do better below

Tell us how we can improve this post?

About

Elvis Plesky
Our fun and curious team mascot's always plugged into the latest trends. He's here to share his knowledge and help you solve your tech problems.

    Leave a Comment

    Start typing and press Enter to search