Connection and use of Git and GitHub under Linux

Source: Internet
Author: User
Tags hosting git client ssh server using git git commands

A simple understanding of Git's ideas and basic working principles, can be better to further and use Git. When you start to learn git, it's best not to confuse Git's concepts with other version control systems such as Subversion, which can be confusing to the actual meaning of each operation.

Git is a free, distributed version Control tool, or a source code management tool that emphasizes fast. Each git working directory is a completely separate code base with complete history and version tracking capabilities, independent of the network and hub servers.

When you manage a project, Git has three working areas locally: Git's local data directory, working directory, and staging area. As shown in the following:

So there are only three states in Git for any file: committed (committed), modified (modified), and staged (staged).

After a simple look at git, the next thing to do is install the GIT client with the following command:

Install Git

However, after you install the GIT client, if your code is not hosted on GitHub, you can skip setting up your GitHub account content, or you'll need to configure your GitHub account, and GitHub provides SSH support for the managed Git repository. That is, the user can connect to GitHub's SSH server in a public-key authentication way. Before you can use git commands to download and push code.

First, you need to register an account with https://github.com/ : Just click on "Signup and Pricing" in the navigation bar, or click the big "plans, Pricing and Signup" button in the home page, The Introduction and registration page of the fee scheme is entered. Open source software Hosting is the cornerstone of GitHub, and GitHub is free for hosting open source project repositories (i.e., non-private repositories). In the fee scheme and registration page, the top one is the free hosting solution for open source, as shown in.

Click on the "Create a free Account" button on the right to go to the registration page, as shown in.

Registration requires only the user name, email address and password to be entered. Note: Each email address can only be registered once. After the registration is completed, the newly registered account will be automatically logged in. As shown in the following:

Click the Settings button in the upper right corner to access the Settings page, our main concern is "setting up Git and SSH keys", the user can use public key authentication to connect to GitHub SSH server.

We first use the SSH command to connect to the github.com SSH service, the login user name is git (all GitHub users share this SSH user name, do not write other).

ssh-t [email protected] After execution prompt: Permission denied (PublicKey).

This means that we have not properly set up the public key authentication in the GitHub account. To set the interface for GitHub's SSH public key:

GitHub's SSH service supports public key authentication in the OpenSSH format and can create a public/private key pair via the ssh-keygen command under Ubuntu.

"[email protected]"-f ~/.  Ssh/github  

You can also use the ssh-keygen command to create multiple public keys with different names, which is important when you have multiple github accounts. This is because while a GitHub account allows multiple different SSH public keys, in turn, an SSH public key can only correspond to one GitHub account.

Next, copy the contents of the ~/.ssh/github.pub file to the Clipboard. The public key is a long string, if you open the public key file with the editor will be broken line display, note that in the copy must not insert extra line breaks, spaces, etc., otherwise in the public key authentication process because the server side and the client public key does not match to cause authentication failure. Then paste the contents of the public key file into GitHub's SSH Public Key Management dialog box, the key dialog, and name the SSH key and save it. Once the settings are successful, accessing GitHub with an SSH command will display an authentication success message and exit. The user name corresponding to the public key is also displayed in the Authentication success information.

SSH-T [email protected] After execution prompt: Hi github! You'vesuccessfully authenticated, but GitHub does not provide shell access. 

With the above settings, we are able to access the GitHub hosting server directly using the git command via SSH. So, let's start using Git for version control:

1. Download the code from the server, and accurately copy a repository from the GitHub server to the Local:

mkdir gitmkdir reposcd git/reposgit clone [email protected]:"accountcontext"/"  Repos name". Git         

2. Once the source code has been acquired, it can be developed, and it will be ready to be submitted after the development is complete:

git Add.    //Add added and modified files to the staging area, do not process deleted files git status   "Commit directions//Refer to code to local data directory, and add commit instructions 

3. It is possible that you and others to change the same file, then the conflict situation is unavoidable, then after the submission of the code, will prompt the code conflict files, we need to do is to deal with these conflicts, and resubmit:

Git pull     "commit directions"  

4. When you are done with the above steps, you need to synchronize the repository data of the local data directory to the GitHub server so that your colleagues can see the changes you made:

git push

Note: The content in "" requires the reader to write the appropriate content according to his or her actual situation.

The main purpose of this article is to enable programmers to quickly get started with git and GitHub, hoping to help.

Connection and use of Git and GitHub under Linux

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.