Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

$ git checkout BRANCH_NAME

Synopsis

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

...

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

Options:

  • -q , --quiet : Quiet, suppress feedback messages.
  • --progress : Progress status is reported on the standard error stream by default when it is attached to a terminal, unless --quiet is specified.
  • -f , --force :When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
  • -b <new_branch> : Create a new branch named <new_branch> and start it at <start_point>
  • -B <new_branch> : Creates the branch <new_branch> and start it at <start_point>; if it already exists, then reset it to <start_point>. This is equivalent to running "git branch" with "-f".
  • -t , --track  : When creating a new branch, set up "upstream" configuration.
  • --no-track : Do not set up "upstream" configuration, even if the branch.autoSetupMerge configuration variable is true.

Examplechecks out the rdk-next branch.

$ git checkout rdk-next

checks out the rdk-next branch.

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]

  • -n  , --dry-run :Don’t actually add the file(s), just show if they exist and/or will be ignored.
  • -v , --verbose :Be verbose.
  • -f , --force      :Allow adding otherwise ignored files.
  • -i , --interactive : Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree.
  • -p , --patch   : Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.
  • -e , --edit  :Open the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and apply the patch to the index.
  • -u ,–update :Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.

...

Example

$ git add Documentation/\*.txt

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

...

.

...

commit

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

$ git commit

Synopsis: Synopsis 

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

...

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

Options:

  • -a , --all : Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
  • --p , --patch : Use the interactive patch selection interface to chose which changes to commit.
  • -C <commit> ,  --reuse-message=<commit> : Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
  • -c <commit> , --reedit-message=<commit> : Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.
  • --squash=<commit> : Construct a commit message for use with rebase --autosquash
  • --branch : Show the branch and tracking info even in short-format.
  • -F <file> , --file=<file> : Take the commit message from the given file. Use - to read the message from the standard input.

Example:

$ edit hello.c
$ rm goodbye.c
$ git commit -a

...

$ 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:

  • -d , --delete : Delete a branch.
  • -D : Shortcut for --delete --force.
  • --create-reflog : Create the branch’s reflog. 
  • -f , --force :  Reset <branchname> to <startpoint>, even if <branchname> exists already. Without -f, git branch refuses to change an existing branch.
  • -m , --move :Move/rename a branch and the corresponding reflog.
  • -c ,--copy     :Copy a branch and the corresponding reflog.
  • -l , --list         :List branches. With optional <pattern>..., e.g. git branch --list 'maint-*', list only the branches that match the pattern(s).
  • -a , --all        :List both remote-tracking branches and local branches. Combine with --list to match optional pattern(s).
  • --show-current : print the name of the current branch. In detached HEAD state, nothing is printed.

Example:

creating a new git branch called “dev”

$$ git branch dev
Deletedcreating a new git branch devcalled “dev”
$ git branch -d dev

Deleted branch dev

merge

Merges [branch] into current branch.

$ git merge [branch]

Synopsis: Synopsis 

git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
	[--no-verify] [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
	[--[no-]allow-unrelated-histories]
	[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>…​]
git merge (--continue | --abort | --quit)

Options:

  • --commit : Perform the merge and commit the result.
  • -e,–edit : Invoke an editor before committing successful mechanical merge to further edit the auto-generated merge message, so that the user can explain and justify the merge.
  • --log[=<n>] : In addition to branch names, populate the log message with one-line descriptions from at most <n> actual commits that are being merged.
  • --progress  , --no-progress :Turn progress on/off explicitly. If neither is specified, progress is shown if standard error is connected to a terminal. 

diff

Shows diff of the unstaged changes.

...

$ git diff

Shows diff of the staged changes.

...

  • -F <file > ,       --file=<file> : Read the commit message to be used for the merge commit (in case one is created).
  • --overwrite-ignore , --no-overwrite-ignore :Silently overwrite ignored files from the merge result. This is the default behavior. Use --no-overwrite-ignore to abort.
  • --abort  :Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
  • --quit :Forget about the current merge in progress. Leave the index and the working tree as-is.
  • --continue :After a git merge stops due to conflicts you can conclude the merge by running git merge --continue

Example

$ git merge fixes enhancements

Merge branches fixes and enhancements on top of the current branch, making an octopus merge.

diff

Show changes between commits, commit and working tree, etc

$ git diff

Synopsis

git diff [<options>] [<commit>] [--] [<path>…​]
git diff [<options>] --cached [<commit>] [--] [<path>…​]
git diff [<options>] <commit> <commit> [--] [<path>…​]
git diff [<options>] <blob> <blob>
git diff [<options>] --no-index [--] <path> <path>

Options

  • -p,--patch :Generate patch
  • -U <n> ,      --unified=<n> :Generate diffs with <n> lines of context instead of the usual three. Implies --patch. Implies -p.
  • --output=<file> :Output to a specific file instead of stdout.
  • --raw :Generate the diff in raw format.
  • --minimal :Spend extra time to make sure the smallest possible diff is produced.
  • --anchored=<text> : Generate a diff using the "anchored diff" algorithm.

Example

$ git diff            (1)
$ git diff --cached   (2)
$ git diff HEAD       (3)
  1. Changes in the working tree not yet staged for the next commit.

  2. Changes between the index and your last commit; what you would be committing if you run "git commit" without "-a" option.

  3. Changes in the working tree since your last commit; what you would be committing if you run "git commit -a"

log

Shows the history of the current branch.

...