The use of Git

Source: Internet
Author: User
Tags git commands

First, install git1, Windows install a Git2, Linux under the Yum (apt-get) Install Git second, use Git to connect to GitHubWhen you use Git to connect to GitHub, you need to put an SSH public key generated under Linux on GitHub. 1), generate the public key
Ssh-keygen-t rsa-c "[Email protected]"
Then the system prompts to enter information such as the location of the file, three consecutive hit return, the resultingThe SSH key file is saved in the ~/.ssh/id_rsa.pub file. 2) Get the public keyunder Linux, you can use the cat command to display the contents of the Id_rsa.pub ( cat ~/.ssh/id_rsa.pub), and then copy its contents. Under Windows , open the file with a text editing tool, and then copy its contents. 3) Paste on GitHub

Then copy all the contents of the. ssh/id_rsa.pub file and paste it into the add SSH key interface in GitHub account management .

Note 1: Use VIM to read Git_home /.ssh/id_rsa.pub you may have more space and line breaks when you copy the public key content to the GitHub Web site when you need to delete it. Therefore, it is recommended to use cat to read the SSH public key. Once the SSH public key is successfully added to GitHub, you can use the command SSH-T [email protected] to verify success. If out of the phenomenon: Hi xxx. You've successfully authenticated, but GitHub does not provide shell access. The connection was successful.

Note 2: The generated SSH public key should be placed under Git's account (unfortunately, I failed to connect successfully.) You can use the command SSH-TV [email protected] to find the reason for failure. Through the detailed debug process, I found that like I put my ssh key information into the/home/admin/.ssh/, and the test using the account is root, the path to find the SSH key is root/.ssh, so permission denied. Su to admin, you can connect successfully ~ ~)

For detailed instructions, see: http://blog.sina.com.cn/s/blog_6b706e15010199p1.html

3. Using Git and github to manage your code

3.1 Create a new repository

Use the GitHub online tutorials here. Make sure that Git has a version of at least 1.7.10, otherwise it may not succeed. For details on how to use it, see: Https://help.github.com/articles/set-up-git. You cannot create a new repo under Linux, only the repo that are already in GitHub can be modified. So, when you want to create a new repo, you must create a new one on github.com, and then add new content to this repo by using Git under Linux.

3.2 Modifying the code in repo

GitHub's official web site also has a tutorial to modify the repo code. For details, see: Https://help.github.com/articles/fork-a-repo. The brief steps are as follows:

$git clone https://github.com/username/spoon-knife.git$cd spoon-knife$git add filename.py #添加文件到版 This library $git commit-m ' add filename.py to src ' #提交, generating a version record, note that the code is still local $vim readme.md #修改S Readme.md file content in Poon-knife $git commit-m ' Modify the readme.md '  #提交, generate version history, note that the code is still local $git [remote] RM file name1.py #删除repo中的filename1. py file $git commit-m ' delete filename1.py ' #提交, resulting in a version record, note that the code is still Local $git push Origin #将修改提交到github上 <br>

3.3 Common git commands
git Help #可查看git的常用命令git config--global user.name "Your name Here" #设置commit的署名 git config--global user.email "[email protected]" #设置commit的emailgit config [--local|--global|--system]--list/ -L #查看本地的global信息git config [--local|--global|--system]--unset[-all] user.name #删除user. Name information. If user.name corresponds to multiple values, Unset-all can be used to remove git remote add XXX https://github.com/username/repo_name.git #设置github的连接git clone git ://github.com/your_account/aimed_repo.git #复制一个repo到本地 git remote-v #查看本地设置的url连接信息 g It status #查看当前工作的branch git branch #查看本地所有的branch git branch -A #查看远程的所有分支 git branch-d branch_name #删除本地branch_name这一分支 git push o Rigin--delete branch_name #删除名为branch_name的远程分支 git checkout branch_name #切换到名为 Branch_name's branch on git chechout-b branch_name                        #在本地新建一个名为branch_nam的分支 git diff test_branch_name #查看当前branch与test_branch_ The difference between code in name git mv filename newfilename #文件重命名 git push XXX branch_name #上传指定的b                             Ranch to the remote git pull #将远程上的版本与本地版本进行合并, equivalent to get fetch + git merge git reset--hard Cancel the operation #将刚才进行的git pull to restore the original copy code before the local version merge

4. How to delete repository on GitHub

The ability to delete repo on the GitHub page is relatively covert and is to be a table here. For example, you want to delete a repo named Python. First click on "Python", click "Settings", find "delete this repository", confirm the deletion. Note that the repo on GitHub cannot be restored after it has been deleted Oh ~ ~


The use of Git

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.