How to use git to upload project code to GitHub

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

Objective:

GitHub is a git-based code hosting platform, where paid users can build private warehouses, and our general free users can only use public repositories, which means the code is open. This is enough for the average person to have a public warehouse.

Steps:

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


2. Installing the client Tortoisegit
GitHub is the server, to use Git on their own computer We also need a GIT client, I choose Tortoisegit here, he gives us a graphical interface operation. Need to install first before installing

githttp://msysgit.github.com/;

tortoisegit:http://code.google.com/p/tortoisegit/
After loading, right mouse will have a few more options, such as: Git Init hear, git Bash, git Gui.


3. Configure Git

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 to go to the GIT command line and configure SSH key to upload the local repository to GitHub.

2) Create an SSH key locally
$ ssh-keygen-t rsa-c "Your_e[email protected]"

The following [email protected] changed to your mailbox, then asked to confirm the path and enter the password, we use the default all the way to the line. Successful words will be generated under ~/. SSH folder, go in, open id_rsa.pub, copy the key inside. Go back to GitHub, go to account Settings, choose SSH keys,add ssh key,title on the left, and paste the Key.

3) Verify success, enter in Git bash

$ ssh-t [email protected]

If it is the first time will prompt whether continue, enter Yes 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.name "your name" $ git config--global user.email "[Email protected]"

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.


4.Submit Upload

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

$ git Add README

$ git commit-m "first commit"

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 .


5. 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's help

Git show # shows the content of a commit git show $id

Git co--<file> # Discard workspace Modifications

Git Co. # Discard Workspace Modifications

git add <file> # Commit working file modifications to local staging area

git Add. # submit all the modified work files to staging area

git rm <file> # remove files from repository

git rm <file>--cached # Remove files from repository without deleting files

git reset <file> # recover from Staging area to working file

git reset--. # Recover from Staging area to working file

git Reset--hard # Restores the state of the last commit, discarding all of the changes since the previous commit

Git ci <file> git ci. 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, and the restore action itself also creates a commit object

git revert HEAD # Restores the state of the last commit


View File diff
git diff <file> # Compare current file and staging area file diff git diff

git diff <id1><id2> # Compare the differences between two commits

git diff <branch1>. <branch2> # Compare between two branches

git diff--staged # compare staging area and repository differences

git diff--cached # compare staging area and repository differences

git diff--stat # just compare statistics


View Commit Record
git log git log <file> # View the file for each commit record

git log-p <file> # view diff for each detail change

Git log-p-2 # See a diff of the last two detailed edits

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 branches that have been merged into the current 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 to the past

git co-b <new_branch> <branch> # Create a new new_branch based on branch

Git Co $id # Checkout A history commit record, but without branching information, switching to another branch will automatically delete

Git co $id-B <new_branch> # Checkout A history commit record and 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 when it needs to be forced)

Branch Merging and Rebase
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 diff >: /sync.patch # Generate Patches

git apply. /sync.patch # Patching

git apply--check. /sync.patch #测试补丁能否成功


Git staging management
Git Stash # Staging

git Stash List # column all stash

git stash apply # recover staged content

git stash Drop # Delete Staging area

GIT Remote branch Management

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

Git pull--no-ff # Crawl all branches of remote repository update and merge to local, do not fast-forward merge

Git fetch origin # crawl Remote repository update

git merge Origin/master # merges the remote main branch into the 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 landlord 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 <local_branch> # Create a remote branch, origin is the remote repository name

Git push Origin <local_branch>:<remote_branch> # Create a remote branch

Git push Origin:<remote_branch> #先删除本地分支 (git br-d <branch>), then push to delete remote branch


GIT Remote repository Management
Git remote-v # View remote server address and warehouse name

git remote Show Origin # View the Server warehouse status

git remote add origin [email protected] Github:robbin/robbin_site.git # Add repository 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 <rep ository> # Deleting a remote 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:~ # Upload the repository to the server

mkdir robbin_site.git && cd robbin_site.git && git--bare init # Create a pure warehouse on the server

git remote add origin [email protected] Github.com:robbin/robbin_site.git # Set up the repository address

Git push-u Origin Master # client First Commit

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

git remote Set-head Origin Master # Set 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


Attached: Msysgit + tortoisegit: Install the Configure Version Control tool on Windows Git graphical use

How to use git to upload project 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.