Github (1)

Source: Internet
Author: User
Tags git commands git shell

It's okay at home over the weekend. I started to go to github and knew about the github open-source community for a long time. But it started yesterday.

Github is a famous open-source community. programmers can share their projects on github. At the same time, github also provides the distributed version control function, many ides provide git-related plug-ins instead of integrating git. I haven't discussed git's rich shell in depth. Let's start with a simple environment:

Register a git account at github.com. After registration, you can change the avatar. The git avatar is hosted by avatar.com. github then obtains the avatar from the avatar api.

Next, let's talk about git's two windows clients,

  1. Github for windows: http://windows.github.com/
  2. Git for windows: https://code.google.com/p/msysgit/downloads/list? Q = full + installer + official + git

The former is an official version of github. It provides the metro-style UI, the creation and management of local git repositories, and the synchronization of github repositories. In addition, it also provides git shell command lines.

The latter is an open-source project on google code. Apart from providing git bash command lines, the former has a different installation path specified by the system, the installation path of the latter is customized by the user. After installation, the path environment variable of git is automatically added for ease of use. After cmd is enabled, enter git and we can see that

1 Microsoft Windows [version 6.1.7601] 2 copyright (c) 2009 Microsoft Corporation. All rights reserved. 3 4 C: \ Users \ yourname> git 5 usage: git [-- version] [-- exec-path [= <path>] [-- html-path] [-- man-path] [-- info 6-path] 7 [-p | -- paginate | -- no-pager] [-- no-replace-objects] [-- bare] 8 [-- git-dir = <path>] [-- work-tree = <path >] [-- namespace = <name>] 9 [-c name = value] [-- help] 10 <command> [<args>] 11 12 The most commonly used git commands are: 13 add file contents to the index14 bisect Find by binary search the change that introduced a bug15 branch List, create, or delete branches16 checkout Checkout a branch or paths to the working tree17 clone Clone a repository into a new directory18 commit Record changes to the repository19 diff Show changes between commits, commit and working tree, etc20 fetch Download objects and refs from another export grep Print lines matching a variable init Create an empty git plugin or reinitialize an existing one23 log Show commit logs24 merge Join two or more development histories together25 mv Move or rename a file, a directory, or a symlink26 pull Fetch from and merge with another repository or a local branch27 push Update remote refs along with associated objects28 rebase Forward-port local commits to the updated upstream head29 reset current HEAD to specified state30 rm Remove files from the working tree and from the index31 show Show various types of objects32 status Show the working tree status33 tag Create, list, delete or verify a tag object signed with GPG34 35 See 'git help <command> 'for more information on a specific command.36 37 C: \ Users \ yourname>

In this case, we can easily integrate git.exe into the third-party idea. For example, we only need to set the git.exe path.

First, let's talk about how to clone a github project to a local device.

 1 yourname@yourname-PC ~ 2 $ cd ~/path/to/yourproject 3 yourname@yourname-PC ~/path/to/yourproject 4 $ git clone https://github.com/username/projectname 5 Cloning into 'projectname'... 6 remote: Counting objects: 57, done. 7 remote: Compressing objects: 100% (47/47), done. 8 remote: Total 57 (delta 20), reused 36 (delta 7) 9 Unpacking objects: 100% (57/57), done.10 yourname@yourname-PC ~/path/to/yourproject11 $

As long as you know the github address of the project you want to clone, you can clone it. The above uses the https protocol, and of course we can also use the ssh and git protocols.

The synchronization between the local repository and the github server repository is as follows:

After installing the git for windows client, we need to generate the git ssh key, which is the key linked to our local and remote github repository.

First, open git bash and enter the following command:

 1 Welcome to Git (version 1.8.1.2-preview20130201) 2  3 Run 'git help git' to display the help index. 4 Run 'git help <command>' to display help for specific commands. 5 yourname@yourname-PC ~ 6 $ cd ~/.ssh 7 yourname@yourname-PC ~/.ssh 8 $ ssh-keygen -t rsa -C "youremail@example.com" 9 Generating public/private rsa key pair.10 Enter file in which to save the key(/c/Users/yourname/.ssh/id_rsa):11 Enter passphrase again:12 Your identification has been saved in /c/Users/yourname/.ssh/id_rsa.13 Your public key has been saved in /c/Users/yourname/.ssh/id_rsa.pub.14 The key fingerprint is:15 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx youremail@example.com16 yourname@yourname-PC ~./ssh17 $

You can Enter the default path and empty secret number in three Enter keys, or you can customize the path and Enter a custom secret number.

After the ssh key is successfully generated ~ The id_rsa and id_rsa.pub files are displayed in/. ssh/. One is the key and the other is the public key.

After the local ssh key is generated, log on to github, Add the SSH key to the SSH Keys tab of account settings, open id_rsa.pub, and paste the content in the key text box, then Add the SSH key to complete the matching between the local key and the github key.

To test whether the connection with github is successful, run the following command:

1 yourname@yourname-PC ~/.ssh2 $ ssh git@github.com3 Hi youremail! You're successfully authenticated, but GitHub does not provide shell access.4 Connection to github.com closed.5 yourname@yourname-PC ~/.ssh6 $

The prompt message indicating successful authorization is displayed. If the prompt fails, you can run the ssh-add command or find other causes.

So far, we have established an ssh link to the github server, and we can submit the local repository and code changes to github.

In github for windows, open Github and select the repository in local. We can see the recently submitted changes. Of course, we can synchronize the locally submitted changes to github through Sync.

Of course, you can also perform the above operations through git bash:

1 yourname@yourname-PC ~2 $ cd ~/path/to/yourproject3 yourname@yourname-PC ~/path/to/yourproject(master)4 $ git push origin master5 Username for 'https://github.com': youremail@example.com6 Password for 'https://youremail@example.com@github.com':7 Everything up-to-date8 yourname@yourname-PC ~/path/to/yourproject(master)9 $

If you do not use git init to initialize your project, there will be no (master) branches in your project path, so before git push

1 yourname@yourname-PC ~2 $ cd ~/path/to/yourproject3 yourname@yourname-PC ~/path/to/yourproject4 $ git init5 Initialized empty Git repository in c:/Users/yourname/path/to/yourproject/.git/6 yourname@yourname-PC ~/path/to/yourproject(master)7 $

And then git push.

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.