Archie  Clayton

Archie Clayton


Common Git Commands Cheat Sheet

In this tutorial, I have documented some of the common git commands I use on a regular basis or had used a couple of times for a specific purpose. This is definitely not an exhaustive list but more comprehensive and is meant for quick reference.

Initialising/Cloning a GIT repository

To create a new local git repository:

git init

To copy from a local git repository:

git clone /path/to/repository

To copy from a local git repository:

git clone username@host:/path/to/repository

Updating local repository FROM remote repository

To effect (merge) changes from remote to local repository:

git pull


git fetch
git merge <branch_name>

NB: git pull is nothing but git fetch and merge branch under the hood with automatic branching strategies applied.

Git Configuration

To configure an user name and email to a local repository:

git config "your_name"

git config "your_email_address"

To configure an user name and email to all commits:

git config --global "your_name"

git config --global "your_email_address"


To create a new branch and switch:

git checkout -b <branch_name>

To switch to an existing branch:

git checkout <branch_name>

To view working branch:

git branch

To delete a branch:

git branch -d <branch_name>

Adding a change to the local repository

  1. Make changes to the file.
  2. Verify that the file list of changed files together with the files that are yet to be staged or committed:
git status

3. Add the file to staging/index:

git add <file_name>

4 . Commit the staged changes to head:

git commit -m "Your_message_about_the_commit"

To commit any change that has been added to staging and also the files changed thereafter but not yet in staging:

git commit -a "Your_message_about_the_commit"

5. To push changes to the branch:

git push origin <branch_name>

6. To push changes to master:

git push origin master

Ideally, in collaborative software development environment pull requests are used to approve changes made to master. So, we should push our changes to our working branch and open a pull-request to merge the changes.

Working with Git Stash

To record the current state of the working directory and the index and to go back to a clean working directory:

git stash save "your_message"

“your_message” makes it easier to locate the stash state in the stash list.

To get the ordered list of stashed working directories:

git stash list

The output is a numbered list like stash@{0}, stash@{1} and so on.

To clear ALL the stash states:

git stash clear

To drop the selected stash tree, in this case,the second last stashed state:

git stash drop stash@{1}

Default — Last stashed state

To remove the selected stashed state from the stash list and apply on top of the current working tree state:

git stash apply stash@{1}

Default — Last stashed state

To remove the selected stashed state from the stash list and apply on top of the current working tree state. Additionally, it deletes the popped stash state.

git stash pop stash@{1}

Default - Last stashed state

Logs and Histories of GIT commands

To check git command history (only HEAD):

git reflog [show]

To check git command history all:

git reflog show --all

To check all git commands history with time:

git reflog --date=iso

To check all “specific_command” (like pull/ commit/ stash) commands history including time:

git reflog --date=iso|grep specific_command

To view log of commits in a branch:

git log origin/master

#github #gitlab #git 

What is GEEK

Buddha Community

Common Git Commands Cheat Sheet
Myriam  Rogahn

Myriam Rogahn


Basic Git Commands you need to Master

In this part you will get familiar with some basic Git commands. At the end of this blog you will be able to perform certain task like

  • Set up a folder as a Git repository
  • Perform basic Git operations on your Git repository

These are those commands you must conquer

Basic Git Commands

  • At any location on your computer, create a folder named git-test.
  • Open this git-test folder in your favorite editor.
  • Add a file named index.html to this folder, and add the following HTML code to this file:
<!DOCTYPE html>

<h1>Sab Batade Aapko</h1>

Initializing the folder as a Git repository

  • Go to the git-test folder in your cmd window/terminal and type the following command at the prompt to initialize the folder as a Git repository:
git init

this command will make a file named .git

#github #git #basic-git-commands #git-commands #git-status

7 Best Practices in GIT for Your Code Quality

There is no doubt that Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Still, developers struggle for code quality. Why? They fail to follow git best practices. In this post, I will explain seven core best practices of Git and a Bonus Section.

1. Atomic Commit

Committing something to Git means that you have changed your code and want to save these changes as a new trusted version.

Version control systems will not limit you in how you commit your code.

  • You can commit 1000 changes in one single commit.
  • Commit all the dll and other dependencies
  • Or you can check in broken code to your repository.

But is it good? Not quite.

Because you are compromising code quality, and it will take more time to review codeSo overall, team productivity will be reduced. The best practice is to make an atomic commit.

When you do an atomic commit, you’re committing only one change. It might be across multiple files, but it’s one single change.

2. Clarity About What You Can (& Can’t) Commit

Many developers make some changes, then commit, then push. And I have seen many repositories with unwanted files like dll, pdf, etc.

You can ask two questions to yourself, before check-in your code into the repository

  1. Are you suppose to check-in all these files?
  2. Are they part of your source code?

You can simply use the .gitignore file to avoid unwanted files in the repository. If you are working on more then one repo, it’s easy to use a global .gitignore file (without adding or pushing). And .gitignore file adds clarity and helps you to keep your code clean. What you can commit, and it will automatically ignore the unwanted files like autogenerated files like .dll and .class, etc.

#git basics #git command #git ignore #git best practices #git tutorial for beginners #git tutorials

Rupert  Beatty

Rupert Beatty


Git Commands You Can Use To Dig Through Your Git History

In this short article, we’ll be exploring some quick  git commands that can help us in digging through our repositories’ history of commits. We’ll look at

  1. git log
  2. git shortlog
  3. git show
  4. git rev-list

#git #git-log #git-commands #git-history #aws

Madyson  Reilly

Madyson Reilly


Best Practices for Using Git

Git has become ubiquitous as the preferred version control system (VCS) used by developers. Using Git adds immense value especially for engineering teams where several developers work together since it becomes critical to have a system of integrating everyone’s code reliably.

But with every powerful tool, especially one that involves collaboration with others, it is better to establish conventions to follow lest we shoot ourselves in the foot.

At DeepSource, we’ve put together some guiding principles for our own team that make working with a VCS like Git easier. Here are 5 simple rules you can follow:

1. Make Clean, Single-Purpose Commits

Oftentimes programmers working on something get sidetracked into doing too many things when working on one particular thing — like when you are trying to fix one particular bug and you spot another one, and you can’t resist the urge to fix that as well. And another one. Soon, it snowballs and you end up with so many changes all going together in one commit.

This is problematic, and it is better to keep commits as small and focused as possible for many reasons, including:

  • It makes it easier for other people in the team to look at your change, making code reviews more efficient.
  • If the commit has to be rolled back completely, it’s far easier to do so.
  • It’s straightforward to track these changes with your ticketing system.

Additionally, it helps you mentally parse changes you’ve made using git log.

#open source #git #git basics #git tools #git best practices #git tutorials #git commit

Royce  Reinger

Royce Reinger


The Most Common Git Commands

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

#various #git #git commands #github #plesk git