GitHub uploads projects

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

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

"[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.

"[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

"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

GitHelp <Command># Show Command Helpgit show# Show content for a commit git show $idgit co--<file># Discard workspace Modify Git Co.# Discard workspace Modify git add <file> # 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 # delete 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 working file git reset--hard # restore the state that was last submitted, That is, discard all changes to git ci <file> git ci after the last commit.                                    Git ci -a # git Add, git rm and git ci are all combined to do Git ci-am "Some comments" git ci--amend # modify last commit record git revert < $id > # restore the state of a commit, the restore action itself also creates a commit object git revert HEAD # restore status of last commit            


View File diff

# Just to compare statistical information




View Commit Record

Log-p-#查看提交统计信息


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 new branch git br-v # View the last commit information for each branch git br--merged # View the branch that has been merged into the current branch git br--no-merged # View the branch that has 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 a new New_branchgit co # to checkout a history commit record, But without branching information, switching to another branch will automatically delete the Git co  $id-B <new_branch> # Make a history commit record checkout out, create a branch git br -d <branch> # Delete a branch git br-d <branch> # Force a branch to be removed (the branch that has not been merged is removed when it needs to be forced)     



Branch Merging and Rebase

# rebase Master to branch, equivalent to: Git co <branch> && git rebase master && git co master && git Me Rge <branch>



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

#测试补丁能否成功




Git staging management

# Trace a remote branch to create the appropriate local branch git Co-b <# Create a local branch based on a remote branch, same as above



Git push # push all branches

# Push the local landlord branch to remote (if no remote main branch is created, used to initialize remote repository) Git push origin <# Create remote Branch, origin is the remote repository name Git push Origin <#先删除本地分支 ( Git br-d <branch>), and then push to delete the remote branch 




GIT Remote repository Management

# Set the remote warehouse address (used to modify the remote warehouse address) git remote RM <repository> # Delete the repository



Create a remote Warehouse

# Set head of remote repository to point to 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 ....

GitHub uploads projects

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.