User Tools

Site Tools


This is an old revision of the document!

Back to Developers Page


a) Getting help:

  • Show help for a command
    • git help command OR git command –help

b) Repository creation:

  • Create a repository in the current directory
    • git init
  • Clone a remote repository into a subdirectory
    • git clone url

c) File operations:

  • Add file or files in directory recursively
    • git add path
  • Remove file or directory from the working tree
    • git rm path
      • -f : Force deletion of file(s) from disk

6. git mv path destination

  Move file or directory to new location
  1. f : Overwrite existing destination files

7. git checkout [rev] file

  Restore file from current branch or revision
  1. f : Overwrite uncommitted local changes

d) Working tree:

8. git status

  Show status of the working tree

9. git diff [path]

  Show diff of changes in the working tree

10. git diff HEAD path

  Show diff of stages and unstaged changes

11. git add path

  Stage file for commit

12. git reset HEAD path

  Unstage file for commit

13. git commit

  Commit files that has been staged (with git-add)
  1. a : Automatically stage all modified files

14. git reset –soft HEAD^

  Undo commit & keep changes in the working tree

15. git reset –hard HEAD^

  Reset the working tree to the last commit

16. git clean

  Clean unknown files from the working tree

17. git stash

  Record the current state of the working directory and clean it

e) Examining History:

18. git log [path]

  View commit log, optionally for specific path

19. git log [from[]]

  View commit log for a given revision range
  1. -stat : List diffstat for each revision
  1. S'pattern' : Search history for changes matching pattern

20. git blame [file]

  Show file annotated with line modifications

f) Remote repositories - remotes:

21. git fetch [remote]

  Fetch changes from a remote repository

22. git pull [remote]

  Fetch and merge changes from a remote repository

23. git push [remote]

  Push changes to a remote repository

24. git remote

  List remote repositories

25. git remote add remote url

  Add remote to list of tracked repositories

g) Branches:

26. git checkout branch

  Switch working tree to branch
  1. b branch : Create branch before switching to it

27. git branch

  List local branches

28. git branch -f branch rev

  Overwrite existing branch, start from revision

29. git merge branch

  Merge changes from branch

h) Exporting and importing:

30. git apply - < file

  Apply patch from stdin

31. git format-patch from[]

  Format a patch with log message and diffstat

32. git archive rev > file

  Export snapshot of revision to file
  1. -prefix=dir/ : Nest all files in the snapshot in directory
  1. -format=[tar|zip] : Specify archive format to use: tar or zip

i) Tags:

33. git tag name [revision]

  Create tag for a given revision
  1. s : Sign tag with your private key using GPG
  1. l [pattern] : List tags, optionally matching pattern

j) File status flags:

M (modified) : File has been modified

C (copy-edit) : File has been copied and modified

R (rename-edit) : File has been renamed and modified

A (added) : File has been added

D (deleted) : File has been deleted

U (unmerged) : File has conflicts after a merge

Back to Developers Page

git_reference.1486091289.txt.gz · Last modified: 2017/03/11 18:22 (external edit)