Saturday, December 31, 2011

Frequently Used Git Commands with Github

simple log of personal usage.

Add tag

1. add: git add -a TAG_NAME (then git bash will ask you to add tag message)

2. prerss 'I', input some message, press 'ESC', input 'wq' then press 'ENTER'

3. push tag: git push --tags

Clone a project
git clone [url] : clone by url

Create a file
touch [fileName]

add changed:
before commit the any change, you should add it
git add [the file path to add] : add specific file
git add . : add all

git add -A : also remove index of deleted files
(will add new files, as well as updating modified content in your index, and remove files that are no longer in the working directory.)
Reference: Removing Deleted Files from your Git Working Directory

revert change:
git reset --hard : reset HEAD, index and working tree
git reset [--<mode>] [<commit>]
This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>, which must be one of the following:
   -q, --quiet           be quiet, only report errors
   --mixed               reset HEAD and index
   --soft                reset only HEAD
   --hard                reset HEAD, index and working tree
   --merge               reset HEAD, index and working tree
   --keep                reset HEAD but keep local changes
   -p, --patch           select hunks interactively

commit changed:
before push the added change to git, you should commit it
git commit -m [message]


branch
You may want to keep current snapshot and also keep going, branch it
git branch [new_branch_name] : create local branch
git branch [new_branch_name] [from_branch_name] : create branch [new_branch_name] from branch [from_branch_name]
git branch -d [branch_name] : delete branch
git checkout [branch_name] : switch to branch
git branch : show all branchs and currently working branch

after a branch created and switched to it,
you can add/delete/modify files and add - commit - push as usual
for example,

git checkout [branch_name]
git touch test
git add test
git commit -m 'test branch'
git push origin [branch_name]


push to Github
git push origin master

No comments:

Post a Comment