Git usage-How to upload a local project to GitHub (two easy and convenient ways)

Source: Internet
Author: User
Tags comments commit diff file diff ssh git clone git commands

Upload your local project to GitHub (two easy and easy ways)


One, the first method:

First you need a GitHub account, and all you have to do is register.

https://github.com/

we use git to install the Git tool first, here is the download address, download the same way to install directly:

https://git-for-windows.github.io/

1. Go to GitHub home page and click New Repository to create an item

2. Fill in the appropriate information and click Create

Repository Name: Warehouse names

Description (optional): Introduction to Warehouse Description

Public, Private: Warehouse permissions (publicly shared, private, or designated collaborators)

Initialize This repository with a README: Add a readme.md

Gitignore: A repository type that does not need to be versioned, corresponding to the makefile. Gitignore

License: Certificate type, corresponding build file license

4. Click Clone or dowload an address will appear, copy this address for backup.

5. Next to the local operation, first right click on your project, if you have previously installed git successfully, the right button will appear two new options for the Git Gui here,git bash here, where we choose Git bash here, into the following interface, Test_ Bluetooth is the name of my project.

6. Then enter the following code (the key step) to clone the repository above GitHub to a local

git clone https://github.com/CKTim/BlueTooth.git (Https://github.com/CKTim/BlueTooth.git replaced with the address you copied earlier)

7. After this step your local project folder will be more folder, the folder name is your github above the project name, as shown in the figure I have a test folder, we put all the files under the Local project folder (in addition to the newly-created folder), The rest is copied to the new, more-out folder,

8. Then continue to enter the command CD test, go to the test folder

9. Then enter the following code to complete the rest of the operation:

git Add. (Note: Don't forget the back., this action is to add the files under the test folder)

git commit-m "Submit Information" (Note: "Submit information" in exchange for your needs, such as "first commit")

Git push-u Origin Master (Note: This is done to push the local repository to GitHub, this step requires you to enter your account and password)


two, the second method:


The first step: we need to first create a local repository (in fact, a folder).

You can right-click to create a new folder, or you can open a git bash command-line window by right-clicking the command.

Now I'll create a new test folder on my desktop from the command line (you can also make this folder anywhere else) and go to this folder


Step Two: Turn this folder into a git manageable repository by ordering git init

At this point you will find that there is a. git folder in test, which is used by Git to track and manage your repository. If you don't see it, because it's hidden by default, you need to set it up so that the hidden file is visible.


Step three: This time you can paste your project into this local git repository (after pasting you can view your current status through Git status) and then add the project to the repository (or git add) via git Add. Add all the files in this directory to the repository, Note that the points are separated by a space). In this process you can actually always use git status to see your current status.


Here you are prompted to paste the item, but not add it to the Git repository, and then we'll add it through git. All the items you just copied are added to the warehouse.


Fourth step: Commit the project to the repository with Git commit.

-M behind the quotation mark is the submission of the comment content, this can not be written, but it is best to write, or will error, the details of Google itself. Okay, we're done with our local git repository, and here's the connection to the remote repository (that is, GitHub).

Because the transfer between the local git repository and the GitHub repository is encrypted via SSH, the connection needs to be set up:

Fifth step: Create SSH KEY. Take a look at your C-drive user directory there is no. ssh directory, some words to see if there is no Id_rsa and id_rsa.pub these two files, have jumped to the next step, did not create by the following command

   $ ssh-keygen-t rsa-c "youremail@example.com"
Then return all the way. At this point you will find the Id_rsa and id_rsa.pub two files in the. SSH directory under the user.

Sixth step: Login to GitHub, find the upper right corner of the icon, open the point into the inside of the settings, and then select the inside of the SSH and GPG keys, click on the upper right corner of the new SSH key, and then the title filled, then put just id_ Rsa.pub inside the content copied to the title under the Key Content box, and finally click on the Add SSH key, so that the completion of the SSH key encryption. Specific steps can also be seen below:




Seventh step: Create a git repository on GitHub.

You can create a new repository directly, for example, I created a TEST2 repository (because I already have a test repository in it, so I can't create a test repository anymore).

Eighth step: After creating a git repository on GitHub, we can associate with the local repository, which can be entered at the command line of the local test repository, depending on the prompt to create a good git repository page:

$ git Remote add Origin https://github.com/guyibang/TEST2.git

Note that origin is appended with the address of the warehouse you created on GitHub.

Nineth step: After the connection, we can push all the contents of the local library to the remote Repository (GitHub), by:

$ Git push-u Origin Master
Because the new remote warehouse is empty, so to add-u this parameter, and so on the remote repository inside the content, the next time from the local library upload content only then can be:
$ GIT push origin master

The process of uploading a project may take a while to complete:

This time you re-refresh your github page into the newly created warehouse and you will find that the project has been successfully uploaded:

This completes the entire process of uploading the local project to GitHub.

In addition, there is a pit to note, is in the seventh step above the creation of the remote repository, if you check the Initialize this repository with a readme (that is, when the warehouse is created automatically to create a Readme file), So in the Nineth step, when you push the local repository content to the remote repository, you report a failed to push some refs to https://github.com/guyibang/TEST2.git error.


This is because the Readme file in your newly created warehouse is not in the local repository directory, so we can merge the following commands first:

$ git Pull--rebase Origin master

Then you can push and you will succeed.


Summary: In fact, only the following steps will be able to upload local projects to GitHub

1. Create a repository (i.e. a folder) locally and turn it into a git repository via git init;

2. Copy the project into this folder and add it through git. Adding items to the warehouse;

3, then through the git commit-m "comment content" to submit the project to the warehouse;

4. After setting the SSH key on GitHub, create a new remote repository to associate the local repository with the remote repository via git remote add Origin https://github.com/guyibang/TEST2.git;

5, finally through the GIT push-u origin master to push the local warehouse project to the remote repository (that is, GitHub), (if the new remote repository automatically created a Readme file will be error, the solution to see above).

Third,git commands

view, add, submit, delete, retrieve, reset modified files

git help <command> # Show Command's help

git show # Show content of a commit git show $id

git co--<file> # Discard workspace Modify

g It co. # Discard Workspace Modify

git add <file> # Commit work file modification to local staging area

git Add. # Submit all modified work files staging area

git rm <file> # delete files from repository C6/>git RM <file>--cached # Remove files from repository, but do not delete files

git reset <file> # Restore from staging area to working file

git reset--. # Restore from Staging area to work  File

git reset--hard # Restores the state of the last commit, that is, discard all changes to

git ci <file> git ci after the previous commit. Git ci-a # git add, git rm and git CI and other operations are merged together to do git ci-am "some comments"

git ci--amend # Modify the last commit record

git Reve RT < $id > # Restores the state of a commit, the recovery action itself also creates a commit object

git revert HEAD # Restores the state of the last commit


View File diff

git help <command> # Show Command's help

git show # Show content of a commit git show $id

git co--<file> # Discard workspace Modify

g It co. # Discard Workspace Modify

git add <file> # Commit work file modification to local staging area

git Add. # Submit all modified work files staging area

git rm <file> # delete files from repository C6/>git RM <file>--cached # Remove files from repository, but do not delete files

git reset <file> # Restore from staging area to working file

git reset--. # Restore from Staging area to work  File

git reset--hard # Restores the state of the last commit, that is, discard all changes to

git ci <file> git ci after the previous commit. Git ci-a # git add, git rm and git CI and other operations are merged together to do git ci-am "some comments"

git ci--amend # Modify the last commit record

git Reve RT < $id > # Restores the state of a commit, the recovery action itself also creates a commit object

git revert HEAD # Restores the state of the last commit



View Commit record

git log git log <file> # View this file every time you submit a record

git log-p <file> # view diff

git log-p-2 # To see the last two changes in detail diff

git log--stat #查看提交统计信息


TIG

you can use TIG instead of diff and Log,brew install TIG on your Mac


Git Local Branch Management
View, toggle, create, and delete branches

Git br-r # View remote branch

git BR <new_branch> # Create a new branch

git br-v # View the last commit information for each branch

git br--merged # view that has been merged into the current branch Branch

git br--no-merged # View branches that have not been merged into the current branch

git Co <branch> # Switch to a branch

git co-b <new_branch> # Create a new branch, And switch past

git co-b <new_branch> <branch> # based on branch create new New_branch

git co $id # Checkout A history commit record, But without branching information, switching to another branch will automatically delete the

git co $id-B <new_branch> # Checkout A History commit record, create a branch

git br-d <branch> # Delete a Branch

git br-d <branch> # Force a branch to be removed (the branch that is not merged is removed and needs to be forced)


Branch Merging and Reba

git merge <branch> # Merge branch branches into the current branch

git merge origin/master--no-ff # do not fast-foward merge so you can generate a merge commit

git rebase master <branch> # rebase Master to branch, equivalent to: Git co <branch> && git rebase master && ; Git co master && git merge <branch>


git patch management (for easy development of synchronization on multiple machines)

git merge <branch> # Merge branch branches into the current branch

git merge origin/master--no-ff # do not fast-foward merge so you can generate a merge commit

git Rebase Master <branch> # will master rebase to branch, equivalent to: Git co <branch> && git rebase master && gi T Co master && git merge <branch>



git Staging tube

Git stash # staged

git stash List # column all stash

git stash apply # recover staged content

git stash drop # Delete staging area

git remote branch management

G It pull # Crawl all branches of remote repository update and merge to local

git pull--no-ff # crawl remote repository All branch updates and merge to local, don't fast-forward merge

Git fetch origin # crawl remote repository update

git m Erge Origin/master # Merge Remote Master Branch to local current branch

git co--track origin/branch # Track a remote branch to create the appropriate local branch

git co-b <local_branc H> origin/<remote_branch> # Create local branch based on remote branch, same as above



git push # push all branches

Git push Origin Master # pushes the local host branch to the remote main branch

Git push-u Origin master # pushes the local landlord branch to the remote (if no remote main branch is created for initializing the remote repository)

git push Origi n <local_branch> # Create remote Branch, origin is remote repository name

Git push Origin <local_branch>:<remote_branch> # Create remote Branch C5/>git Push Origin:<remote_branch> #先删除本地分支 (git br-d <branch>), and then push to delete the remote branch



git remote Warehouse tube

Git remote-v # View remote server address and warehouse name

git remote Show origin # View remote Server warehouse status

git remote add Origin git@ Github:robbin/robbi N_site.git # Add remote warehouse address

git remote set-url Origin git@ Github.com:robbin/robbin_site.git # set remote Warehouse address (used to modify remote warehouse address) Git re Mote RM <repository> # Delete Remote repositories



Create a remote warehouse

git clone--bare robbin_site robbin_site.git # Create a version-only warehouse with a versioned project

scp-r my_project.git git@ git.csdn.net:~ # to upload a repository to the server C3/>mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure repository

git Remote add Origin g on the server it@ Github.com:robbin/robbin_site.git # Set remote warehouse address

Git push-u Origin Master # client First commit

Git push-u origin Develop # First commit a local develop branch to a remote develop branch, and track

git remote set-head Origin Master # Sets the remote repository head to the master branch



You can also command settings to track remote libraries and local libraries

Git branch--set-upstream master origin/master

git branch--set-upstream develop Origin/develop




Method one turn from: http://www.cnblogs.com/cxk1995/p/5800196.html

Method two turn from: http://blog.csdn.net/zamamiro/article/details/70172900

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.