Skip to content

Instantly share code, notes, and snippets.

@kamalbanga
Created July 24, 2014 13:43
Show Gist options
  • Save kamalbanga/23ff43ac7366a65169e4 to your computer and use it in GitHub Desktop.
Save kamalbanga/23ff43ac7366a65169e4 to your computer and use it in GitHub Desktop.
Git commands

INITIALISING

$ git init [project-name] Creates a new local repository with the specified name

$ git clone https://github.com/[organization]/[repository].git Clones the repo into a new filder named ‘repository’

$ git status Lists all new or modified files to be committed

$ git --version Show the git version.

COMMIT

$ git add [file] Snapshots the file in preparation for versioning

$ git commit -m "[descriptive message]" Records file snapshots permanently in version history

$ git commit -am “[descriptive message]” Flag ‘a’ is used to directly commit a file without staging

$ git tag “[tag name]” A tag reference is created which points to the current commit.

$ git branch Lists all local branches in the current repository

$ git branch [branch-name] Creates a new branch

$ git checkout [branch-name] Switches to the specified branch and updates the working directory

$ git shortlog -ns Most common committers

LOG

$ git log --oneline Lists version history for the current branch

$ git log --oneline --all Shows complete log irrespective of current checked out commit

$ git log --reverse Reverse log

$ git tag -n List all tags along with messages

$ git branch -a List all branches

$ git branch -r Show all remote branches

$ git log tag1..tag2 Show log between two tags

CONFIG

$ git config --global user.name “Kamal Banga” Set username.

$ git config --global user.email “kamal@sigmoidanalytics.com” Set email.

$ git config --list List all settings.

PUSH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment