A concise tutorial on Github
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 install download git OSX version download git Windows version git Linux version configuration git
First, SSH key is created locally;
$ ssh-keygen-t rsa-c "your_email@youremail.com"
The following your_email@youremail.com changes to the mailbox you registered on GitHub, and then asks for a confirmation path and a password, which we use as a default return 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 generated on your computer.
In order to verify success, enter it under GIT bash:
$ ssh-t git@github.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.
$ git config--global user.name "your name"
$ git config--global user.email "your_email@youremail.com"
Go to the repository you want to upload, right-click Git Bash, add remote address:
$ git Remote add Origin git@github.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 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:
If this is the repository on the remote server, your command will look like this:
git clone username@host:/path/to/repository
Work Flow
Your local repository consists of three "trees" maintained by git. The first one is your working directory, it holds the actual file, the second is staging area (Index), it's like a cache area, temporarily saves your changes, and finally the HEAD, which 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 "code submission Information"
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> tags
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 displaying history, each submitted message displays only one line:
git config format.pretty Oneline
Interactively add files to staging area:
git add-i links and Resources Graphical Client gitx (L) (OSX, open source software) Tower (OSX) Sou Rce Tree (OSX, free) GitHub for Mac (OSX, free) gitbox (OSX, App Store) guidelines and manuals git community reference professional git thinking git like git Hub Help diagram Git related articles A concise guide to GitHub: http://rogerdudler.github.io/git-guide/index.zh.html How to use GitHub efficiently: http://www.yangzhiping.com/tech/github.html