Thursday, July 3, 2014

Notes on Git and Github

##############################################
# Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/[username]/[project name]
git push -u origin master

##############################################
# Push an existing repository from the command line

git remote add origin https://github.com/[username]/[project name]
git push -u origin master


##############################################
# Create new local clone from a remote project:
git clone https://github.com/[username]/[project name]

##############################################
# Push to remote repository after update local files (in "git add .", dot "." means all changed files)
git add .
git commit -m "..."
git push -u origin master


##############################################
# Revert to a previous version [5]

# Shows all previous versions with hash value
git log --oneline
# Checkout given version given hash value. Change will be saved to repository
git checkout <hash>
# Checkout individual file. Will be saved to repository as change
git checkout <hash> <filename>
# Checkout most recent version
git checkout master


##############################################
# Other commands

# Show status of local repos
git status

# Update local files from remote repos
git pull

# More commands by usage frequency
git diff
git log
git mv
git rm

git tag
git branch
git merge

git checkout
git fetch
git grep
git reset
git rebase

# In general, get help information.
git help

usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=] [--work-tree=]
           [-c name=value] [--help]

           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help <command>' for more information on a specific command.



##############################################
# Difference of git add -A, ., -u [6].



##############################################
# github usage:
[1] https://help.github.com/articles/creating-releases
[2] Git Tutorial
[3] A successful Git Branching Model
[4] Github md file formatting
[5] Undoing git changes
[6] Difference of git add -A, ., -u


No comments:

Blog Archive

Followers