Git Command Referrence

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

checkout

To switch to another branch in your local work environment.

$ git checkout BRANCH_NAME

Synopsis: 

git checkout [-q] [-f] [-m] [<branch>] 

git checkout [-q] [-f] [-m] --detach [<branch>]

git checkout [-q] [-f] [-m] [--detach] <commit>

git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]

git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <pathspec>…​

git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] --pathspec-from-file=<file> [--pathspec-file-nul]

git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>…​]

Options:

Example

checks out the rdk-next branch.

$ git checkout rdk-next

add

To stage changes[file modifications and deletions].Accepts arguments for files or directories within the project directory. 

$ git add

Synopsis: 

git add [--verbose | -v]      [--dry-run | -n]    [--force | -f]    [--interactive | -i]     [--patch | -p]     [--edit | -e]     [--[no-]all | --[no-]ignore-removal | [--update | -u]]    [--intent-to-add | -N]   [--refresh] 

             [--ignore-errors]  [--ignore-missing]     [–renormalize]        [--chmod=(+|-)x]    [--pathspec-from-file=<file> [--pathspec-file-nul]]         [--] [<pathspec>…​]

Options:

$ git add [options]

Examples:

Adds content from all *.txt files under Documentation directory and its subdirectories.

$ git add Documentation/\*.txt

commit

Consists of a snapshot of the directory structure and file contents for the entire project.Record changes to the repository.

$ git commit

Synopsis: 

git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [–amend]

                 [--dry-run] [(-c | -C | --fixup | --squash) <commit>]

                 [-F <file> | -m <msg>] [--reset-author] [--allow-empty]

                 [--allow-empty-message] [--no-verify] [-e] [–author=]

                 [--date=<date>] [--cleanup=<mode>] [--[no-]status]

                 [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]

                 [-S[<keyid>]] [--] [<pathspec>…​]

Options:

Example:

$ edit hello.c
$ rm goodbye.c
$ git commit -a
The command git commit -a first looks at your working tree, notices that you have modified hello.c and removed goodbye.c, and performs necessary git add and git rm for you.

branch

To view a list of existing branches

$ git branch

Creates a new topic branch

$ git branch [branch]

Synopsis: 

git branch [--color[=<when>] | --no-color] [--show-current]
	[-v [--abbrev=<length> | --no-abbrev]]
	[--column[=<options>] | --no-column] [--sort=<key>]
	[(--merged | --no-merged) [<commit>]]
	[--contains [<commit]] [--no-contains [<commit>]]
	[--points-at <object>] [--format=<format>]
	[(-r | --remotes) | (-a | --all)]
	[--list] [<pattern>…​]
git branch [--track | --no-track] [-f] <branchname> [<start-point>]
git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
git branch --unset-upstream [<branchname>]
git branch (-m | -M) [<oldbranch>] <newbranch>
git branch (-c | -C) [<oldbranch>] <newbranch>
git branch (-d | -D) [-r] <branchname>…​
git branch --edit-description [<branchname>]

Options:

Example:

creating a new git branch called “dev”

$ git branch dev
Deleted branch dev
$ git branch -d dev

merge

Merges [branch] into current branch.

$ git merge [branch]

diff

Shows diff of the unstaged changes.

$ git diff

Shows diff of the staged changes.

$ git diff --cached

log

Shows the history of the current branch.

$ git log

Shows the commits that aren't pushed.

$ git log m/[codeline]..

rebase

Reapply commits on top of another base tip.

$ git rebase [options]
$ git rebase [-i | --interactive] [<options>] [--exec <cmd>]
	[--onto <newbase> | --keep-base] [<upstream> [<branch>]]
 git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
	--root [<branch>]
 git rebase (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)

Options :

stash

Stash the changes in a dirty working directory away.when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit. 

$ git stash list [<options>]
 git stash show [<options>] [<stash>]
 git stash drop [-q|--quiet] [<stash>]
 git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
 git stash branch <branchname> [<stash>]
 git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
	     [-u|--include-untracked] [-a|--all] [-m|--message <message>]
	     [--] [<pathspec>…​]]
 git stash clear
 git stash create [<message>]
 git stash store [-m|--message <message>] [-q|--quiet] <commit>

Options :