Reprinted from: http://www.cnblogs.com/fnng/archive/2012/01/07/2315685.html
I. GitHubCreate a project
After logging on to the system, go to GitHubHome page, click in the lower right corner of the page"New repository"
Enter the project information:
Project name: Hibernate-demo
Description: My first project
Click"Create Repository"Now a project has been completed inGitHub.
Note: We createdGitHubA warehouse can only store (or correspond to) One project in a warehouse.
After creating a warehouse,GitHubI have already given you a prompt: When you have read myArticleLet's take a look at this prompt.
Global setup:
Set up git
Git config -- global user. Name "your name"
Git config -- global user. Email defnngj@gmail.com
Next steps:
Mkdir hibernaet-demo2
CD hibernaet-demo2
Git init
Touch readme
Git add readme
Git commit-m'first commit'
Git remote add origin git@github.com: defnngj/hibernaet-demo2.git
Git push-u origin master
Existing git Repo?
CD existing_git_repo
Git remote add origin git@github.com: defnngj/hibernaet-demo2.git
Git push-u origin master
Importing a subversion Repo?
Click here
When you're done:
Continue
Ii. Create a key
How can we make localGitProject and remoteGitHubWhat about establishing a connection? The secret. In other words, it's a password! (The old king of kings, the river demon in Pagoda town ..)
$ Cd ~ /. Ssh check the SSH key of the Local Machine
If the prompt is no such file or directoryIt indicates that this is your first useGit.
If this is not the first time, perform the following operations:,Clear existingSSHKey.
$ Mkdir key_backup
$ CP id_rsa * key_backup
$ RM id_rsa *
Generate a new key:
Ssh-keygen-t rsa-C defnngj@gmai.com"
Note:Enter your own email address. When you press enter, you will be prompted to enter a password, which will be used when you submit the project. If it is blank, you will not need to enter the password when submitting the project. This setting prevents others from submitting content to your project.
Open localC: \ Documents ents and Settings \ Administrator \. Ssh \ id_rsa.pubFile. This file contains the adult key generated just now.
LoginGitHubSystem. ClickAccount settings ---> SSH public keys ---> Add another public keys
Copy the locally generated key to it (KeyText Box ), ClickAdd keyJustOKNow
InGitRun the following command:
$ Git-T git@github.com
If the prompt is: Hi defnngj you 've successfully authenticated, but GitHub does not provide shell access.The connection is successful..
3. Set User Information
This step is not very important and does not seem to work,GitHubThere are official steps, so I will mention them here.
InGitSet the user name and email address
$ Git config -- global user. Name "defnngj" // give yourself a username
$ Git config -- global user. Email "defnngj@gmail.com" // enter your mailbox
InGitHub.Account settings ---> account admin,Find the information:
Your API token is e97279836f0d424a3954c1193dba522f --- keep it secret! Changing your password will
Generate a new token
$ Git config -- Global GitHub. User defnngj // user name on GitHub
$ Git config -- Global GitHub. Token e97279836f0d424a3954c1193dba522f
---- // Git
The above are all preparations, once completed, no need to set up later. The following content is a highlight.
Let's talk about it first.GitCommon basic operations, andLinuxSystem operations are the same:
$ Ls view the content of the current directory
$ CD/D switch to d Disk
$ CD Java/open the Java directory under the current directory
$ Cd j (Table key) If you want to open the Java directory with only one directory starting with J in the current directory, enter J and then press the table key on the disk.
$ CD .. back to the upper-level directory
Assume that you have created a new project and want to submit itGitHubAbove?
Assume that you have created a project and switched to the root directory of the project:
$ Git status//Check the status of all the files in the current project. If it is the first time, you will find that all files are red, because they have not been handed overGit/GitHubManagement.
$ Git add. //(.).GitManagement, that is, submittedGit.
PS: GitIs a concept of a local repository. If there is no network, you can submit the updated content to the local repository first.
$ Git commit-M "New natter"//Describe the content you have updated or modified.
$ Git remote add origin git@github.com: defnngj/hibernate-demo.git
// If you submit a project for the first time, this sentence is very important. This is the connection between your local project and the remote warehouse.
PS:OriginYou can change it to another person's name, but you also need to use your modified name for the next push (COMMIT.
$ Git remote-V// View the repository address that is remotely connected to your current project.
$ Git push-u origin master// Submit the local project to the remote repository.
------------------------------------------------------------
Suppose that you are back home and want to clone the project submitted by the company to your local computer?
If this is the first time you want to clone a GitHub project to a local location or clone another project to a local location.
$ Git clone git@github.com: defnngj/hibernate-demo.git// Switch to the file directory where you want to store the project under git, and run this command to clone the project.
If this project already exists locally, and there is a new update in the repository, how can we merge it into a local project?
$ Git fetch Origin// Obtain the remote update. The remote update is required.
$ Git merge origin/Master// Merge the updated content to the local branch/Master
-------------------------------------------
How do I submit files deleted from the project?
If the remote warehouse has saved the AAA file, I fetch it and deleted the AAA file. I want to push it to the remote warehouse, and the project in the remote warehouse is overwritten by new modifications (that is, AAA in the remote warehouse is also deleted)
$ Git status// You can see which files we have deleted.
$ Git add.// Submit the deleted files to git for management.
$ Git RM src/COM/hzh/hibernate/Dao/AAA. Java// Remove the deleted file. Otherwise, git will not allow us to submit the file to the remote repository.
PS: If you want to delete a directory (Java package), here you want to remove the contents of the entire directory.
$ Git RM src/COM/hzh/hibernate/BBB/-R//-RAll contents in the BBB/directory are moved at one time.
------------------------------------------------------------------------
A new warehouse is created remotely, and a new project is created locally. How can a new project correspond to a warehouse?
In fact, this is also very simple, but I didn't quite understand those commands at the time, so I was vague and did not know how to match them.
$ Git remote add origin git@github.com: defnngj/hibernate-demo.git
// You can add this statement before pushing the project.
Git@github.com: defnngj/hibernate-demo.git The address of your common new repository.GitSwitch to the new projectPushPreviously, with this sentence added, the new warehouse we created is connected to the new project.