github--turn

Source: Internet
Author: User
Tags hosting ruby on rails

A concise tutorial on Github categoryProgramming techniques

If you are a coder, but you do not know GitHub, then I think you are not a rookie level of coder, because you are not really coder, you are just a code porter.

But if you're already reading this article, I think you already know about GitHub.

It is github that makes social programming a reality.

What is Github?

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.

Github was founded in April 2008 by Chris Wanstrath, PJ Hyett and Tom Preston-werner, three developers. So far, it has 59 full-time employees, mainly providing git-based version hosting services.

At the moment, the GitHub adventure has won. Based on a description of GitHub from Wikipedia, we can visualize the growth rate of GitHub:

Today, GitHub is:

    • A community of 1.43 million developers. Among them are top hackers such as the Linux inventor Torvalds, and young geeks such as Rails founder DHH.
    • The most popular open source hosting service on the planet. Currently hosting 4.31 million Git projects, not only are more and more well-known open source projects moving into GitHub, such as Ruby on Rails, JQuery, Ruby, ERLANG/OTP, and nearly three years of popular open source libraries often start on GitHub, for example: BootStrap, node. js, Coffescript, etc.
    • Alexa Global rankings 414 website.
Register your account and create a warehouse

The first step to using GitHub is, of course, registering a GitHub account, the GitHub website address: https://github.com/. 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.

Github Installation
    • Download git OSX version
    • Download git Windows edition
    • Download the git Linux version
Configure Git

First, create a localssh key;

$ ssh---"[email protected]"   

Later, [email protected] instead of the email you registered on GitHub, you will be asked to confirm the path and enter the password, and we'll use the default return line. Successful words will be generated in the ~/ next .ssh folder, go in, open id_rsa.pub , copy inside key .

Go back to GitHub, go to account Settings, choose SSH keys,add ssh key,title on the left, and paste the Key generated on your computer.

In order to verify success, enter it under GIT bash:

-T [email protected].  COM  

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.

The next thing we need to do is upload the local repository to GitHub, and then we'll have to set up username and email, because GitHub will record them each time it commits.

--Global user." Your name "--global user." [Email protected] "        

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

$ git Remote add origin [email protected].  COM: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.

Create a new folder, open it, and then execute it  git init to create a new git repository.

Check out the Warehouse

Execute the following command to create a cloned version of the local repository:

/Path/to/     

If this is the repository on the remote server, your command will look like this:

git clone [email protected]:/path/to/repository    
Work flow

Your local repository consists of three "trees" maintained by git. The first one is yours 工作目录 , it holds the actual file; the second is 暂存区(Index) that it's like a cache area that temporarily saves your changes, HEAD and finally, it points to the result of your last commit.

You can make changes (add them to staging area) by using the following command:
git add <filename>
git add *
This is the first step in the Git basic workflow, using the following command to actually commit the changes:
git commit -m "代码提交信息"
Now, your changes have been submitted to HEAD, but not to your remote repository.

Push changes

Your changes are now in the HEAD of the local repository. Execute the following command to commit the changes to the remote repository:
git push origin master
You can replace master with any branch you want to push.

If you have not cloned an existing repository and want to connect your warehouse to a remote server, you can add it using the following command:
git remote add origin <server>
So you can push your changes to the server you added.

Branch

Branches are used to insulate the development of features. When you create a warehouse,master is the "default" branch. Develop on other branches, and then merge them onto the main branch when you are finished.

Create a branch called "feature_x" and Switch to the past:
git checkout -b feature_x
Switch back to the main branch:
git checkout master
Then delete the new branch:
git branch -d feature_x
Unless you push the branch to the remote repository, the branch is not visible to others :
git push origin <branch>

Update and merge

To update your local repository to the latest changes, do the following:
git pull
To get (fetch) in your working directory and Merge (merge) remote changes.
To merge other branches into your current branch (for example, Master), execute:
git merge <branch>
In both cases, Git will try to automatically merge the changes. Unfortunately, this may not be successful every time, and there may be conflicts (conflicts). You will need to modify these files to manually merge these conflicts (conflicts). After you've changed, you'll need to execute the following commands to mark them as merged successfully:
git add <filename>
Before merging the changes, you can preview the differences using the following command:
git diff <source_branch> <target_branch>

Label

Creating labels for software releases is recommended. This concept is already in existence and is also available in SVN. You can create a label called 1.0.0 by executing the following command:
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff is the first 10 characters of the commit ID you want to tag. You can get the commit ID using the following command:
git log
You can also use a little less commit ID before several, as long as it's pointing is unique.

Replace local changes

If you make a mistake (of course, this should never happen), you can replace the local change with the following command:
git checkout -- <filename>
This command replaces the files in your working directory with the latest content in the HEAD. Changes that have been added to staging area and new files are not affected.

If you want to discard all your local changes and commits, you can get the latest version history on the server and point your landlord branch to it:
git fetch origin
git reset --hard origin/master

Practical Tips

Built-in graphical git:
gitk
Color git output:
git config color.ui true
When the history is displayed, only one row is displayed for each submitted message:
git config format.pretty oneline
Interactively add files to staging area:
git add -i

Linking and resource graphical clients
    • GITX (L) (OSX, open source software)
    • Tower (OSX)
    • Source Tree (OSX, free)
    • GitHub for Mac (OSX, free)
    • Gitbox (OSX, App Store)
Guides and Manuals
    • Git Community Reference Book
    • Professional Git
    • Think like Git.
    • GitHub Help
    • Diagram Git
Related articles
    • A concise guide to Github: http://rogerdudler.github.io/git-guide/index.zh.html
    • How to use github:http://www.yangzhiping.com/tech/github.html efficiently

github--turn

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.