github(2)Github Basics and Remote Repositories
Chapter 1 Getting Started
1.1. About Version Control
Local Version Control
----> Centralized Version Control System(CVCS, CVS, Subversion, Perforce)
----> Distributed Version Control System (DVCS, Git, Mercurial, Bazaar, Darcs)
1.2. Git Basic
Git does not care about the file differences, but saves all snapshot of all the files.
3 Status of the files
committed ----> modified ---> staged(it is in the commit list)
3 working area
Working directory ----> Staging area -----> git directory(repository)
1.3. Windows Install
http://code.google.com/p/msysgit
>git --version
git version 1.7.9.msysgit.0
user information
>git config --global user.name luohuazju
>git config --global user.email luohuazju@gmail.com
check the configuration file
>git config --list
getting help
>git help <verb>
Chapter 2 Git Basics
2.1 Getting a Git Repository
Initializing a Repository in an Existing Directory
Go to the project's directory and type
>git init
This creates a new subdirectory named .git that contains all of your necessary repository files.
>git add readme.txt
>git commit -m "create repository"
After this, we have a git repository with tracked files.
>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
error message:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Cloning an Existing Repository
>git clone git://github.com/luohuazju/cat.git
or
>git clone git://github.com/luohuazju/cat.git cat
2.2 Recording Changes to the Repository
Checking the Status of Your Files
>git status
Tracking New Files
>git add filename
Staging Modified Files
>git add filename
Ignoring Files
>vi .gitignore
*.[oa] #ignore the files .o or .a
!lib.a #do track lib.a, even though you are ignoring .a files above
build/ #ignore all files in the build/ directory
doc/*.txt #
Viewing Your Staged and Unstaged Changes
Committing Your Changes
>git commit
or
>git commit -m "message"
Removing Files
>git rm filename
Moving Files
>git mv file_from file_to
2.3 Viewing the Commit History
Simple command
>git log
Using a GUI to Visualize History
2.4 Undoing Things
Unstaging a Staged File
>git reset HEAD t2.txt
Unmodifying a Modified File
>git checkout -- filename
2.5. Working with Remotes
You can have several remote servers. You can pushing and pulling data to and from remote repositories when you need to share work.
Showing Your Remotes
>git remote
It lists the shortnames of each remote handle.
>git remote -v
origin git://github.com/luohuazju/cat.git (fetch)
origin git://github.com/luohuazju/cat.git (push)
Adding Remote Repositories
>git remote
>git remote add origin git://github.com/luohuazju/magic.git
>git remote -v
origin git://github.com/luohuazju/magic.git (fetch)
origin git://github.com/luohuazju/magic.git (push)
>git fetch origin
Pushing to Your Remotes
>git push [remote-name] [branch-name]
>git push origin master
There are some error message, so I change the remote like this.
>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
solution:
Set Up SSH Keys
step1: open Git Bash
>cd ~/.ssh
step2: I already have this directory. Backup and remove existing SSH Keys.
>mkdir key_backup
>cp known_hosts key_backup/
>rm known_hosts
step3: Generate a new SSH key.
>ssh-keygen -t rsa -C "luohuazju@gmail.com"
>start.
I open the directory on win7 and get the key file id_rsa.pub.
step4:Add my SSH Key to GitHub
Account Setting--->SSH Keys ----> Add New SSH key
step5: Test everything out
>ssh -T git@github.com
Everything works fine now.
Inspecting a Remote
>git remote show [remote-name]
Removing and Renaming Remotes
>git remote rename first_name second_name
>git remote rm remote_name
references:
http://progit.org/book/zh/
http://progit.org/book/ch2-1.html
http://progit.org/book/ch2-5.html
http://sillycat.iteye.com/blog/1323263
http://sillycat.iteye.com/blog/1131274
http://sillycat.iteye.com/blog/1074171
http://sillycat.iteye.com/blog/689970
http://help.github.com/ssh-issues/
http://help.github.com/linux-set-up-git/
http://help.github.com/win-set-up-git/
Chapter 1 Getting Started
1.1. About Version Control
Local Version Control
----> Centralized Version Control System(CVCS, CVS, Subversion, Perforce)
----> Distributed Version Control System (DVCS, Git, Mercurial, Bazaar, Darcs)
1.2. Git Basic
Git does not care about the file differences, but saves all snapshot of all the files.
3 Status of the files
committed ----> modified ---> staged(it is in the commit list)
3 working area
Working directory ----> Staging area -----> git directory(repository)
1.3. Windows Install
http://code.google.com/p/msysgit
>git --version
git version 1.7.9.msysgit.0
user information
>git config --global user.name luohuazju
>git config --global user.email luohuazju@gmail.com
check the configuration file
>git config --list
getting help
>git help <verb>
Chapter 2 Git Basics
2.1 Getting a Git Repository
Initializing a Repository in an Existing Directory
Go to the project's directory and type
>git init
This creates a new subdirectory named .git that contains all of your necessary repository files.
>git add readme.txt
>git commit -m "create repository"
After this, we have a git repository with tracked files.
>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
error message:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Cloning an Existing Repository
>git clone git://github.com/luohuazju/cat.git
or
>git clone git://github.com/luohuazju/cat.git cat
2.2 Recording Changes to the Repository
Checking the Status of Your Files
>git status
Tracking New Files
>git add filename
Staging Modified Files
>git add filename
Ignoring Files
>vi .gitignore
*.[oa] #ignore the files .o or .a
!lib.a #do track lib.a, even though you are ignoring .a files above
build/ #ignore all files in the build/ directory
doc/*.txt #
Viewing Your Staged and Unstaged Changes
Committing Your Changes
>git commit
or
>git commit -m "message"
Removing Files
>git rm filename
Moving Files
>git mv file_from file_to
2.3 Viewing the Commit History
Simple command
>git log
Using a GUI to Visualize History
2.4 Undoing Things
Unstaging a Staged File
>git reset HEAD t2.txt
Unmodifying a Modified File
>git checkout -- filename
2.5. Working with Remotes
You can have several remote servers. You can pushing and pulling data to and from remote repositories when you need to share work.
Showing Your Remotes
>git remote
It lists the shortnames of each remote handle.
>git remote -v
origin git://github.com/luohuazju/cat.git (fetch)
origin git://github.com/luohuazju/cat.git (push)
Adding Remote Repositories
>git remote
>git remote add origin git://github.com/luohuazju/magic.git
>git remote -v
origin git://github.com/luohuazju/magic.git (fetch)
origin git://github.com/luohuazju/magic.git (push)
>git fetch origin
Pushing to Your Remotes
>git push [remote-name] [branch-name]
>git push origin master
There are some error message, so I change the remote like this.
>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
solution:
Set Up SSH Keys
step1: open Git Bash
>cd ~/.ssh
step2: I already have this directory. Backup and remove existing SSH Keys.
>mkdir key_backup
>cp known_hosts key_backup/
>rm known_hosts
step3: Generate a new SSH key.
>ssh-keygen -t rsa -C "luohuazju@gmail.com"
>start.
I open the directory on win7 and get the key file id_rsa.pub.
step4:Add my SSH Key to GitHub
Account Setting--->SSH Keys ----> Add New SSH key
step5: Test everything out
>ssh -T git@github.com
Everything works fine now.
Inspecting a Remote
>git remote show [remote-name]
Removing and Renaming Remotes
>git remote rename first_name second_name
>git remote rm remote_name
references:
http://progit.org/book/zh/
http://progit.org/book/ch2-1.html
http://progit.org/book/ch2-5.html
http://sillycat.iteye.com/blog/1323263
http://sillycat.iteye.com/blog/1131274
http://sillycat.iteye.com/blog/1074171
http://sillycat.iteye.com/blog/689970
http://help.github.com/ssh-issues/
http://help.github.com/linux-set-up-git/
http://help.github.com/win-set-up-git/