How to upload project code to github with Git

Source: Internet
Author: User
Tags diff git client using git git commands

Tag: will initialize tag fast to execute content push mailbox ASC

Register your account and create a warehouse

The first step to using GitHub is, of course, registering a GitHub account. After that you can create a warehouse (free users can only build public warehouses), create a New Repository, fill in the name after create, there will be some warehouse configuration information, this is a simple git tutorial. The steps are as follows:

Open https://github.com Register directly on the home page



Click button to register successfully, select "+" on the user menu above the page->new repository create a new warehouse


Take a name for the warehouse, click the Create Warehouse button you will successfully create a warehouse

Installing the GIT client

GitHub is a server, and we need a git client to use git on our own computer.

Windows users please download http://msysgit.github.com/

Mac users please download http://code.google.com/p/tortoisegit/

All the way next, after the installation succeeds, go back to the C drive, or any folder, click the right mouse button will be a few more menus
such as Git Init hear, git Bash, git Gui, the installation is successful.

Configure Git

Let's find a place in the computer's hard drive to store the local warehouse, for example, we set up the local repository under the C:\MyRepository\1ke_test folder

To enter the 1ke_test folder, right-click the following steps:

1) in the local repository, right-click Git Init here to get a more. Git folder, which means that local git was created successfully. Right-click Git bash into the git command line with the following effect:

For the sake of insurance, we first execute the GIT init command

$ git init

To upload a local repository to GitHub, you need to configure SSH key.

2) Create an SSH key locally

$ ssh-keygen-t rsa-c "[Email protected]"

  

The following [email protected] changed to your mailbox. My email address is [email protected], which is also registered on GitHub:

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

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\lilu\.ssh, where Lilu 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.

Go back to the GitHub website, go to account Settings, and choose SSH keys,add ssh Key on the left.

Title fill, paste key.

3) Verify success, enter in Git bash

$ ssh -T [email protected]

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 to upload the local repository to GitHub, and we'll have to set up username and email before that, because GitHub will record them every time it commits.

$ git config--global user.name "your name" $ git config--global user.email "[Email protected]"

  

Enter the above command line, and my interface is displayed as follows

5) Go to the repository you want to upload, right-click Git Bash, add remote address

$ git Remote add origin [email protected]:yourname/yourrepo.git

  

The following yourname and Yourrepo indicate that you re-github user name and the newly created warehouse, added after the addition of the. git, open config, here will be a remote "origin" content, this is just added to the long-range address, You can also modify config directly to configure the remote address.

corresponding to GitHub

Submit Upload

1) Next add some files to the local repository, such as the Readme

Create a new Readme file locally

Then enter the command at the command line

$ git add readme$ git commit-m "First commit"

  

My execution interface is as follows

2) upload to GitHub

$ 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.

You're done, now you know how to submit your local project to GitHub.

Gitignore file

Gitignore as the name implies is to tell git to ignore the files, this is a very important and useful file. In general, we write the code after the compilation, debugging and other operations, which will produce a lot of intermediate files and executables, these are not code files, do not need git to manage. We see a lot of these files in git status, and if we add them with Git add-a, it's too cumbersome to add them manually. Then we need to gitignore.

git commands

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

git help <command> # show Command helpgit show # shows the content of a commit git show $idgit co--<file> # Discard workspace Modify Git Co. # Discard Workspace Modify git add <file> # to commit working file modifications to local staging area git Add. # Submit all modified work files staging area git rm <file> # delete files from repository git rm <file>--cached # Remove files from repository, but do not delete files git reset <file> # from Staging area restore to working file git reset--. # Restore from staging area to working file git reset--hard # Restores the state of 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 are all combined to make git ci-am "some comments" Git ci--amend # Modify the last commit record git revert < $id > # Restores the state of a commit, the restore action itself also creates a commit object git revert HEAD # Restores the status of the last commit view file Diffgit diff <file> # Compare the differences between the current file and staging area file git diffgit diff <id1><id2> # Compare two commits between Git diff <branch1> <branch2> # Compare Git diff--staged # between two branches compare the staging area and the repository diff git diff--cached # Compare the staging area and the repository diff git diff--stat # Just compare statistics view commit record G  It log git log <file> # View the file every time you submit a record git log-p <file> # view Diffgit log-p-2 # View details of the most recent two changes diffgit log --stat #查See Submit statistics 

  


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 each branch last commit information git br--merged # View the branch that has been merged into the current branch git BR--no-m Erged # 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> # Create new New_branchgit Co $id based on Branch # Checkout a history commit record, but without branching information, switching to another branch will automatically remove the Git co $id-B <new_bra Nch> # Checkout A History commit record, create a branch git br-d <branch> # Delete a branch git br-d <branch> # Force a branch to be deleted (the branch that is not merged is deleted. Force) Branch Merge and Rebasegit Merge <branch> # Merge branch branches into the current branch git merge origin/master--no-ff # do not fast-foward merge, This allows you to generate a merge commit git rebase Master <branch> # will master rebase to branch, equivalent to: Git co <branch> && git rebase mas ter && git Co master && git merge <branch> git patch management (easy to develop sync on multiple machines) git diff >. /sync.patch # Build patch git apply: /sync.patch # Play Patch git apply--check. /sync.patch #测试补丁能否成功 git staging admin git stash # staging git stash List # column all stashgit stash apply # recover staged content git stash drop # DeleteStaging Area git remote branch management git 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 merge 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_branch> 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 to initialize the remote repository) Git push origin <loca L_branch> # Create Remote Branch, origin is remote repository name Git push Origin <local_branch>:<remote_branch> # Create remote branch Git push origin: &L T;remote_branch> #先删除本地分支 (git br-d <branch>), and then push to delete the remote branch

  




GIT Remote repository Management

Git remote-v # View remote server address and warehouse name git remote Show origin # View remote server warehouse status git remote add origin [email protected] Github:robbin/ro Bbin_site.git # Add remote warehouse address git remote set-url origin [email protected] Github.com:robbin/robbin_site.git # Set the remote warehouse address ( Used to modify the remote warehouse address) git remote rm <repository> # Delete a repository

  



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 [email protected] git.csdn.net:~ # will be a pure warehouse Upload to server mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure repository git remote add origin [EM in server]  AIL protected] Github.com:robbin/robbin_site.git # set remote Warehouse address Git push-u Origin Master # client First commit GIT push-u origin develop # The first time a local develop branch is submitted to a remote develop branch, and Trackgit remote Set-head Origin Master # sets the head of the repository to point to the master branch

  




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

Git branch--set-upstream Master origin/mastergit Branch--set-upstream Develop Origin/develop

  

Reprint Address: http://1ke.co/course/194 extended read: http://1ke.co/course/342 at the same time can see the progit.pdf comparison of all git data ....

How to upload project code to github with Git

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.