- Git Commands Cheat Sheet Github
- Github Command Line Cheat Sheet
- Github Commands Cheat Sheet 2020
- Github Commands Cheat Sheet
- Github Git Cheat Sheet
This cheat sheet-style guide provides a quick reference to commands that are useful for working and collaborating in a Git repository. To install and configure Git, be sure to read “How To Contribute to Open Source: Getting Started with Git.” How to Use This Guide: This guide is in cheat sheet format with self-contained command-line snippets. A cheat sheet for VisiData commands. Advanced row selection + regex Select all rows where regex matches the current column + regex Unselect all rows where regex matches the current column. Git Cheat Sheet Create From existing repo From existing data cd /projects/myproject git init git add. Git clone /existing/repo /new/repo git clone git://host.org.
If you have ever worked in web development or in any Software development, then you must have heard of Git, or most probably you have used or using git because it is one of the best version control systems we have. The website GitHub use git version control as its brain. Git provides the best way to manage your project, and it became more helpful when a proper team is working on a project.
Git comes with a standard Command Line Interface (CLI), which mean to interact or work with Git we need to pass commands, though if we are using GitHub for our project rather than using git commands we simply use GitHub buttons and other option to manage our project but it is not necessary that if we are using Git we are using GitHub too, Git and GitHub are two separate entities. Many Developers find using a CLI intriguing because it makes them happy to interact with command lines or terminal or white text on black console, but for a beginner using a command line for git commands becomes a daunting task. Git contains hundreds of commands and it is impossible to learn each of them, so what we do, we just simply learn and practice only those commands which are common and enough to serve our purpose.
So here we have provided a cheat sheet for Git commands, so, you could muddle through if you get stuck somewhere using git or forget some commands.
What is Git?
Git is an open-source distributed version control system and the working principle behind the GitHub website. It is the most famous and widely used version control system of this decade which has huge community support. It is called the Distributed Version control system because, unlike other version control systems that store the project’s full version history in one place, Git allows each developer to have their own local repository with complete proper history changes.
What is Version Control?
A version control system is a software that keeps track of your project history and version.
Git Terminologies
Before reading the git cheat sheet let’s have the look at the basic terminologies we use in git:
Terminology | Description |
Branch | A branch represents the various versions and repositories branching out from your main project. It helps us to keep track of the changes happening in the various repositories. |
Commit | Commit is used to save some changes. |
Checkout | When we switch between branches we use checkout command. |
Fetch | Fetch commands can copy and download the branch file to your local device. |
Fork | A fork is a copy of a repository. |
Head | The commit at the tip of a branch is called the head. It represents the most current commit of the repository you’re currently working in |
Index | If we make any changes in the project in order to save those changes we need to commit them, if not all those changes will remain in the index for commit. |
Master | The main branch of the repositories. |
Merge | If one branch made any changes so, we can use the merge command to make that same changes in all other repositories |
Origin | The default version of a repository |
Pull | It represents the suggestion for changes to the master branch |
Push | It is used to update the remote branch if we have committed the changes |
Repository | It holds all the project’s files |
Tag | It tracks the important commits |
Git Cheat Sheet
Git Commands Cheat Sheet Github
Git Configuration
Commands | Description |
git config –-global user.name “User Name” | Attach the name User Name to the commits and tag |
git config –global user.email “email address” | Attach the email address to the commits and tags |
git config –global color.ui auto | Enable some colorization in Git interface |
Git Setting Project
Commands | Description |
git init [project name] | This command will create a new repository if the project name is provided else it will initialize the git in the current directory. |
git clone [project url] | It will create a clone of the project which is at remote repository project URL |
Git Frequent used commands
Commands | Description |
git status | Show the status of the repository |
git diff [File] | Show changes between the working directory and staging area |
git diff –stages [file] | Show changes between the staging area and index |
git checkout — [file] | Discard change in the working directory |
git add [file] | Add new file |
git reset [file] | Get the file back from the staging area |
git commit | Save the changes |
git rm [file] | Remove the file |
git stash | Put the changes into stash |
Git Branching
Commands | Description |
git branch [-a] | It will show all the branches of the local repository her –a mean all |
git branch [branchname] | Create a new branch |
git checkout [-b] [name] | Switch to name branch, if name is not a branch in the repository so create new branch. |
git merge [branch] | Merge the branch |
git branch –d [branch name] | Remove the branch |
Review Work
Commands | Description |
git log [-n count] | List last n numbers of commit history |
git log –oneline –graph –decorate | Give Overview along with reference label and history graph. |
git log ref. . | List current branch commits |
git reflog | List operations such as commits, checkout, etc. |
Git Tag
Commands | Description |
git tag | Show all tags |
git tag [name] [commit sha] | Create a tag reference named name for current commit |
git tag –d [name] | Remove the tag |
Revert Changes
Commands | Description |
git reset [–hard] [target reference] | Switch current branch to the target reference, and leaves a difference as an uncommitted change. |
git revert [commit sha] | Create a new commit, reverting changes from the specified commit. |
Synchronizing Repositories
Commands | Description |
git fetch [remote] | Fetch the changes from remote |
git pull [remote] | Fetch the changes and merge the current branch with upstream |
git push [remote] | Push all the changes to the remote |
git push –u [remote] [branch] | Push the local branch to the remote upstream |
Conclusion
Git has hundreds of commands and to learn each command is impossible so we only use those commands which are basic and necessary for our project point of view. All the git commands we have provided in this article are the most important git commands and every interviewer expects, you to know at least these commands.
If you like this article or have any suggestion related to the git cheat sheet, please let us know by filling the comment box.
You may be also interested in:
Create repositories
A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.
$ git init
The git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the git init
command, link the local repository to an empty GitHub repository using the following command:
$ git remote add origin [url]
Specifies the remote repository for your local repository. The url points to a repository on GitHub.
$ git clone [url]
Github Command Line Cheat Sheet
Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits
The .gitignore file
Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore
. You can find helpful templates for .gitignore
files at github.com/github/gitignore.
Synchronize changes
Synchronize your local repository with the remote repository on GitHub.com
$ git fetch
Github Commands Cheat Sheet 2020
Downloads all history from the remote tracking branches
$ git merge
Combines remote tracking branches into current local branch
$ git push
Uploads all local branch commits to GitHub
Github Commands Cheat Sheet
$ git pull
Github Git Cheat Sheet
Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull
is a combination of git fetch
and git merge