Git/github getting started

Source: Internet
Author: User

---- // Configure the git/github Environment

1. Create a project on github

After logging on to the system, go to the github homepage and click "New Repository" in the lower right corner of the page"

Enter the project information:

Project name: hibernate-demo

Description: my first project

Click "Create Repository". Now a project is created on github.

Note: We created a github repository where only one project (or project) can be stored.

After creating a repository, github has given you a prompt: after reading my article, you will be very clear about 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 masterExisting Git Repo?
Cd existing_git_repo
Git remote add origin git@github.com: defnngj/hibernaet-demo2.git
Git push-u origin masterImporting a Subversion Repo?
Click here
When you're done:
Continue

 

Ii. Create a key

How can we establish a connection between the local git project and remote github? 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 directory", it indicates that you are using git for the first time.

If this is not the first time, perform the following operations to clear the original ssh key.

$ Mkdir key_backup
$ Cp id_rsa * key_backup
$ Rm id_rsa * generates a new key:

Ssh-keygen-t rsa-C defnngj@gmai.com"

Note: You can 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 the local C: \ Documents ents and Settings \ Administrator \. ssh \ id_rsa.pub file. This file contains the adult key generated just now.

Log on to the github system. Click Account Settings ---> SSH Public keys ---> add another public keys

Copy the locally generated key to it (in the key text box) and click add key.

Run the following command in git:

 

$ Git-T git@github.com if the prompt is: Hi defnngj You 've successfully authenticated, but GitHub does not provide shell access. It means your connection is successful.

 

3. Set User Information

This step is not very important and does not seem to work as well, but it is included in the official github step, so I will also mention it here.

Set the user name and email address in git

 

$ Git config -- global user. name "defnngj" // give yourself a username
$ Git config -- global user. email "defnngj@gmail.com" // enter your mailbox


Find the Account Settings ---> Account Admin in github and 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 several common basic operations in git, which are the same as those in linux:

$ 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

Suppose you have created a new project and want to submit it to github?

 

Assume that you have created a project and switched to the root directory of the project:

$ Git status // view the status of all files in the current project. If it is the first time, you will find it in red because it has not been handed over to git/github for management.

$ Git add. // (.) indicates all the content in the current directory, which is submitted to the local git repository for git management.

Ps: the strength of git is the 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" // describes what 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: the origin can be changed to another person's name, but you should also 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 Under git to the file directory where you want to store this project, 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 remote updates. here we can see that we are preparing to obtain

$ 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 view the 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 file we deleted. Otherwise, git does 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 //-r will move all the content in the bbb/directory 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 is the address of your common new warehouse. Git switches to the new project. Before pushing, add this sentence to connect the created repository to the new project.

 

 

How is it? If you have mastered the above items, can you play them in the project. Git is very powerful. These are just the tip of the iceberg, but it is enough for new users.

Ps: chatting two days ago, a buddy said that he had discovered a good place for Tibetan films. He could manage small movies in the island country, so he was not afraid of personal privacy being discovered by others. Haha, do you want to try it.
 
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.