Upload Project code to github using Git

Source: Internet
Author: User
Tags bz2 commit ssh using git

GitHub is a git-based code hosting platform where we can create our own warehouses (repository), and there are two types of warehouses on GitHub: private repository and public repositories (Public repository), the difference is: a private warehouse You can choose who can see it and who can commit, it is charged; The repository is visible to anyone, anyone can commit, it's free. Public repositories are sufficient for general developers. I. Registering a github account and creating a warehouse

1.1 Registration
Click Sign up in the upper-right corner or enter username, email and password directly in the red box below, then click

1.2 Creating a Warehouse
Creating a warehouse is simple, clicking the + Sign button next to the avatar will jump to the Create warehouse page

Enter the name of the warehouse (required option), item description (optional), properties of the warehouse (public or private), Add gitignore (optional), and license (optional).
Click the Create Repository button and you will successfully create a warehouse. Second, install git

The first step in using Git must be to install Git, because git is not preinstalled on most platforms, and my main working environment is Windows and Linux (Ubuntu), and I think the students who read this article are mostly working on these two platforms. Here's how to install and configure git under these two platforms.

1. Linux (*nix) platform
The original purpose of Linus development of GIT is to develop the Linux kernel service, and it is also the best platform support for Linux. There are several ways to install Git under Linux:
Start with source code (this method is also suitable for most *nix platforms)
Download the latest stable version of the source code from the download page of the Git website, and you can start compiling and installing from the source code:

$ wget http://kernel.org/pub/software/scm/git/git-1.7.3.5.tar.bz2
$ TAR-XJVF git-1.7.3.5.tar.bz2
$ cd git-1.7.3.5
$ make prefix=/usr all; # prefix set your git install directory
$ sudo make prefix=/usr install; # Run as Root

In order to compile Git's source code, we also need some libraries: expat, curl, zlib and OpenSSL, except expat, other libraries may be installed on your machine.
using the installation Package Manager (APT or yum)
Use Yum in systems such as Fedora:

In Debian, Ubuntu and other systems using apt:

$ apt-get Install Git-core

Sometimes, there is a problem with the installation package Manager in your system, or you can download the ". Deb" or ". RPM" installation package from the following site if you are not able to install Git on the Internet or have a compiler.

2. Windows platform
The Windows platform has two tools that mimic the *nix like run environment: Cygwin,msys;git has the appropriate porting version under Cygwin,msys. Personally think Msys platform under the Msysgit best use, I use in Windows is this version.

Below i "wordy" How to install Msysgit under Windows.
Download
Go to its download page to download the latest full install package, https://git-for-windows.github.io/, latest version: 2.6.3.
installation
There is nothing to say in the installation process, which is usually started after installation, all the way to the click "Next". Because of the different line breaks (LF) of the Windows platform's newline characters (CRLF) and the Linux (*nix) platform, there is a place for friends to develop other platform software under Windows (see figure below):

It's best to choose the "Checkout As-is, commit as-is" option here, so git doesn't change the line-break style of your code. Third, configure Git

Under Linux and under Windows to configure Git's approach, just under Linux, you can use git config directly in the command line, and in Windows you will first open "Git Bash", go to the msysgit command line interface, and then git Config command to perform the appropriate configuration operation.
Okay, git is installed in front, and now we're ready to configure
1) The first thing that needs to be configured is the user's username and email, because the content will appear in every commit.

$ git config--global user.name "your name"
$ git config--global user.email "Your_email"

Git configuration information is divided into global and project two, the above command with the "–global" parameter, which means that the global configuration, it will affect every GIT project on this computer.
Git can set different configuration information for each project, and in the command-line environment, go to the directory where the Git project is located and execute the following command:

$ git config user.name "your name"
$ git config user.email "Your_email"

Git's design philosophy, like Linux (*nix), uses "textual" (textuality) as much as possible, storing information in textual form as much as possible, and more so for configuration information, all of which are stored in a text file. The global configuration file for git is stored in the "~/.gitconfig" (. gitconfig) file in the user directory:
We use the cat, Head command to view the global configuration information file

If you are familiar with Git, you can directly modify the "~/.gitconfig", ". Git/config" These two files to configure.

2) Create an SSH key locally
$ ssh-keygen-t rsa-c "Your_email"
Change the your_email back to your email address, which is also the one you registered on GitHub:

To enter directly, the instructions will generate SSH key on the default file Id_rsa.

Because I have been generated before, so it will prompt me already RSA key already exist, direct input y select overwrite can.
Then the system asks for a password, directly press ENTER to indicate that no password is set

Repeat the password is also a direct carriage return, after prompting you shh key has been generated successfully.

Then we go to the prompt address to view the SSH key file. The address of my computer is C:\Users\YULORE-USER.ssh, where Yulore-user is the name of my Computer

Open the Id_rsa.pub and copy the key inside. The key inside is a pair of characters that can not understand the combination of numbers, do not control it, directly copied.

Then go back to the GitHub website and enter settings

Left select ssh keys,add ssh Key

Fill in the title, paste the key, and click the Add Key button.

3) Verify success, enter in Git bash

$ ssh-t git@github.com

Enter will see: You've successfully authenticated, but GitHub does not provide shell access. This means that you have successfully connected to GitHub.

4) The next thing we need to do is create a new warehouse on the local computer.

$ mkdir git_demo
 $cd git_demo
 $ git init

5) Add Remote address
$ git Remote add Origin git@github.com:yourname/yourrepo.git
The following yourname and Yourrepo indicate your github username and the new warehouse you just created.

Execute command

After adding the cat view. Git/config, there will be more than one remote "origin" content, which is just added to the remoting address, you can also directly modify the config to configure the remote address

6) Submit Upload * *
6.1) Next add some files to the local repository and then type the command at the command line

$ git add-a
$ git commit-m "first commit"

My execution interface is as follows

6.2) Push local file to GitHub
Execute command

$ GIT push origin master

The git push command pushes the local repository to the remote server. The git pull command is the opposite.
Note: First commit, Git pull, after modifying the code, use GIT status to view the differences in the file, using git add to add the file to commit.

Now that your local project has been submitted to GitHub.

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.