The quickest way to get started with GitHub

Source: Internet
Author: User

Reference: http://www.w3cschool.cc/w3cnote/git-guide.html

I'm just doing my own practice and slightly revising the tutorials above to help beginners like me get started faster. or refer to here. 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
Let me take the git Windows Edition for example. When the installation is complete, click Git Bash. Configure Git

First, create a localssh key;

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

Behind the[email protected]Instead, you will be asked to confirm the path and enter the password after you have registered on GitHub, we use the default one-way carriage return. The success of the words will be~/Under Build.sshfolder, go in, openid_rsa.pub, copy the Insidekey

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

Let's 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 "[Email protected]"

Create a new folder, open it, and then execute it  git init to create a new git repository. This is the directory where you want to work. (If you want to upload the existing code, you can create a folder here, copy the folder that will be uploaded later)

On the folder, right-click Git bash and add the remote address:

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

The following yourname and Yourrepo indicate your github username and the new repository you just created. (after adding the. git, open config, there will be more than one remote "origin" content, this is just added to the distant address, you can also directly modify config to configure the remote address.) )


It is easy to write the address at the back of origin wrong, and the first command is to delete the wrong origin. The following is added.

Check out the Warehouse

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

Where/path/to/repository as the name implies is the URL address of the code base. Examples are as follows:


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

git clone [email protected]:/path/to/repository
this is actually done. If we are going to upload a folder to this code repository now, here are the steps (with some conceptual explanations):Work flow

CD into the folder, and then copy what you want to pass to the folder.  such as CP to copy the folder. -av (. Indicates the current directory, so you want to be in that folder)

The second command was automatically ignored, and the TAB key was pressed to list the files in the Uvaoj directory.


Your local repository consists of three "trees" maintained by git. The first one is your   working directory , which holds the actual file; the second one is   Staging Area (Index) , it is like a cache area, temporarily save your changes, and finally  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 "代码提交信息"
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 isnot to be seen by others:
git push origin <branch>

Update and merge

To update your local repository to the latest changes, do the following:
git pull
In your working directoryget (Fetch)AndMerging (merge)Far-end 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 may occurconflict (Conflicts)。 You need to modify these files to manually merge theseconflict (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 line is displayed for each submitted message:
git config format.pretty oneline
interactively add files to Staging area:
< Code style= "Font-family:menlo,monaco,consolas, ' Courier New ', monospace; font-size:14.3999996185303px; PADDING:2PX 4px; Color:rgb (199,37,78); Background-color:rgb (249,242,244) ">git add-i

GitHub Novice's fastest way to get started

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.