Installation and use of Git under Linux (GO)

Source: Internet
Author: User
Tags git client using git git commands

Transferred from: http://www.cnblogs.com/sunada2005/archive/2013/06/06/3121098.html

It feels good to be using GitHub recently. Under Windows, you can use the Windows Client (http://windows.github.com/) provided by GitHub. Very stupid, very convenient. How do I use it? See: Http://www.cr173.com/html/15618_1.html. It has recently been discovered that when installing GitHub's Windows client on a corporate computer, it is possible that the company's network speed limit and limit traffic limit are too dead, and how the installation is unsuccessful. The synchronization of the graphics client on github windows at home is also often problematic. No way, you can only connect to GitHub via the text interface. If you have successfully installed GitHub clients on your Windows system, you can use the GitHub bash text client In addition to the graphical client. On my computer, when the graphics client synchronization problems, the text client can still be successful synchronization. If you don't have a GitHub client installed, you can also install other Git bash to connect to GitHub, such as Msysgit (http://msysgit.github.io/). Because the software above is based on git, the syntax is the same as the command used by Linux.

I only used the text interface under Linux, so I installed a git client in text form to connect to GitHub.

1. Install git

I'm using the CentOS system, and when I install Git with yum, I'm prompted not to find a git package. So, you can only install Git in the following ways. Methods see: Http://www.cnblogs.com/Neddy/archive/2011/02/28/1967548.html. There is one problem with the above method: the git download source http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz is given in the method It doesn't seem to work, so I downloaded the latest git install package on the Web and installed it on CentOS. The official website of git under Linux is: Http://git-scm.com/download , maybe because I can not open the network, I do not know how readers you there. If you can't open it, you can find the installation package elsewhere on the web.

2. Using Git to connect to GitHub

When you use Git to connect to GitHub, you need to put an SSH public key generated under Linux on GitHub. For detailed instructions, see: http://blog.sina.com.cn/s/blog_6b706e15010199p1.html. The main commands are:

1 ssh-keygen -t rsa -C"[email protected]"

Then the system prompts for information such as the location of the file save, three consecutive hit enter, the generated SSH key file is saved in the ~/.ssh/id_rsa.pub file.

Use the text Editing tool to open the file, and under 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.

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

Note that when using VIM to read public key content in Git_home/.ssh/id_rsa.pub , there may be more spaces and line breaks that must be deleted when copied to the GitHub site. 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.

Unfortunately, I was unable 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 ~ ~

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                          #添加文件到版本库$git commit -m ‘add filename.py to src‘               #提交,产生版本记录,注意代码依然在本地$vim README.md                             #修改Spoon-Knife中的README.md文件内容$git commit -m ‘modify the README.md‘                 #提交,产生版本记录,注意代码依然在本地$git [remote] rm filename1.py                    #删除repo中的filename1.py文件$git commit -m ‘delete filename1.py‘                  #提交,产生版本记录,注意代码依然在本地$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连接信息
Git status #查看当前工作的
Branch git branch #查看本地所有的
Branch git branch-a #查看远程的所有分支
git branch-d branch_name #删除本地branch_name这一分支
Git push origin--delete branch_name #删除名为branch_name的远程分支
git checkout branch_name #切换到名为branch_name的分支上
git chechout-b branch_name #在本地新建一个名为branch_nam的分支
git diff test_branch_name #查看当前branch与test_branch_name中代码的区别
git mv filename newfilename #文件重命名
git push XXX branch_name #上传指定的branch到远端
Git pull #将远程上的版本与本地版本进行合并, equivalent to get fetch + git merge
Git reset--hard operation canceled #将刚才进行的git pull to restore the original version of the local build before merging

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 ~ ~

5. Git clone/push error message: 14090086:ssl routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing ...

This is due to an error caused by an SSL authentication problem. There are two simple ways to solve this problem:

1. With the command, after successful execution, git clone and git push can be used normally.

git config --global http.sslVerify false

2. Use commands, but each clone and push requires an env portion.

env GIT_SSL_NO_VERIFY=truegit clone https://github.com/XXXX/xxxxx.git

6. What should I do when I have error non-fast-forward on git push? (from: http://blog.csdn.net/chain2012/article/details/7476493)

When you want to push the code to git, a prompt appears:

Error:failed to push some refs to ...

Dealing with "Non-fast-forward" errors
From time to time encounter this error while pushing:

    1. $ GIT push origin master
    2. To.. /remote/
    3. ! [Rejected] master, master (Non-fast forward)
    4. Error:failed to push some refs to '. /remote/'

To prevent-losing history, Non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the ' Non-fast forward '
section of ' Git push--help ' for details.
This error can is a bit overwhelming at first, does not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this was caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using a pull to perform both at once.
In other cases this error was a result of destructive changes made locally by using commands like Git commit--amend or git Rebase. While you can override the remote from adding--force to the push command, you should only do if you are absolutely certa In this is the want to do. Force-pushes can cause issues for other users, which has fetched the remote branch, and is considered bad practice. When in doubt, Don ' t force-push.

The problem (Non-fast-forward) occurs because there is already a part of the code in the Git repository, so it doesn't allow you to overwrite your code directly. So you have 2 ways of choosing:

1, strong push, that is, the use of strong coverage in your local code to replace the contents of the Git repository

Git push-f

2, first fetch git things to your local and then merge and then push

$ git fetch

$ git merge

The 2-sentence command is equivalent to

    1. $ git pull

However, the following problems have arisen:

The above [branch "master"] is what needs to be clarified (. git/config) as follows
[branch "master"]
Remote = origin

Merge = Refs/heads/master

This is tantamount to telling git2 something:

1, when you are in Master branch, the default remote is origin.

2, when you use git pull on Master branch, you don't specify remote and branch, then git uses the default remote (that is, origin) to merge all the changes on the master branch

If you do not want to or do not edit the config file, you can enter the following command line on the bush:

    1. $ git Config branch.master.remote origin
    2. $ git config branch.master.merge refs/heads/master

Then git pull again. Finally git push your code. It works now~

Installation and use of Git under Linux (GO)

Related Article

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.