Uploading local code to GitHub

Source: Internet
Author: User

In fact, GitHub account has been opened, but has not how to upload code, this time in order to find a job, in order to show them my usual code, I intend to put on the desktop of all the small projects are uploaded to GitHub ...

Next I'm going to record the process of uploading the code to GitHub. (Incidentally, I now find it very convenient to use the command line to perform operations in the terminal.) I'm in love with the command line. )

First step: To install git and configure.

If you are using a Mac for development, there are two ways to install Git.

The first method is to install homebrew, and then install git through homebrew, please refer to Homebrew's documentation: http://brew.sh/.

The second way is to install Xcode,xcode integrated git, but it has not been installed for you, you need to run Xcode, choose the Menu "Xcode", "Preferences", in the pop-up window found "Downloads", select "Command Line Tools ", click" Install "to complete the installation.

Xcode can download the installation directly from the AppStore.

Step two: Go to the local project root directory and execute the git command.

CD desktop/learning/Gadgets

Step three: Add all the files of the project to the warehouse

git Add.

If you want to add a specific to a file, you just need to replace it with that particular file.

Fourth step: Commit the Add file to the repository

git commit-m "comment statement"

Fifth step: Go to GitHub and create your own repository. The specific approach is:

After you click New Repository and then click Create Repository, you will be taken to a new page so that you can get the HTTPS address of the new warehouse you created (the URL of the new page). Example: Https://github.com/MelissaHu/Menue

Sixth step: Associate a local warehouse to GitHub

Git remote add Origin https://github.com/MelissaHu/Menue

Seventh step: Pull a bit before uploading to GitHub and execute the following command:

Git pull Origin Master

This is to see if the code is updated (especially when the team is working together, or when a different machine is being developed independently), and you need to pull the latest code into the local repository.

Eighth step: Upload the code to GitHub's remote repository and execute the following command:

Git push-u Origin Master

After the execution, you may need to enter username and password, you only need to enter GitHub's account number and password is OK, if the upload is successful, you can see on the page.

Finally, a record of the implementation process has learned the knowledge point:

1. In the process of uploading the code actually involves two repository, one is the remote repository (on the distant server), the other is the local repository (on your own workspace).

2.git clone is based on your designated remote server/repository/branch, copy a copy to your local, before Git push, your changes to all files are in your own local repository to do, Your changes (local branch) and remote branch are independent and parallel.

3. After clone is complete, Git automatically names this remote repository as origin, downloads all of the data, creates a pointer to its master branch, and uses the remote repository name to represent the remote branch, so origin/ Master points to a remote branch, but you cannot change its data locally.

4.git push Origin Master in Origin specifies which remote you want to push to.

Master is actually a "Refspec", the normal "Refspec" in the form of "+<src>:<dst>", the colon before the name of the local branch , The colon indicates the name of the branch under the remote repository. Note that if you omit <dst>, git thinks you want to push to branch under remote repository with the same name as local branch.

Such as:

$git Push Origin Master:master ( Find the branch named Master in local repository , use it to update the remote repository The next name is Master 's branch, if the remote repository does not exist under the name is master Branch, then create a new one)

$git Push Origin master (omitted <dst>, equivalent to "Git push origin master:master")

$git Push Origin Master:refs/for/mybranch ( Find the branch named Master in local repository , use him to update the remote Repository The following name is Mybranch branch)

$git Push Origin Head:refs/for/mybranch (head points to the current working branch, master does not necessarily point to the branch of the current job, so I think the head It's better than Master. )

$git push Origin:mybranch (again Origin repository inside find mybranch, delete it. Update it with an empty one, which is equivalent to deleting it.)

Uploading local code 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.