git--team to develop the necessary artifacts

Source: Internet
Author: User
Tags using git

Spent two days specializing in git, to organize and share to everyone. Here we begin ...
    • Reprint please specify the source:
    • http://blog.csdn.net/Hello_Chillax/article/details/47405887
    • For more information please visit: http://blog.csdn.net/hello_chillax, thank you
One. Learn to prepare for using Git (under Windows).
    • Install a git locally and install the Gitbash. Not Will install QQ will install Git. )

    • Register an account with the GitHub official online. Give it to a portal. GitHub website

Two. After getting ready, let's first sweep the blinds and talk about concepts.
    • What is the difference between git and GitHub? (Tears have been running ...) )
      A: Git is a local Code version management tool, when we write a project, we will inevitably have to do code management, such as we write the code every day after the total to back up a copy of it, the reason is very simple, in case your workspace (workspace) where the hard drive suddenly hung up, do not say the odds are very small, but, In case it happens.
      We can always feel what it's like to have a relationship between git and GitHub. As we mentioned above, Git is the local Code management tool, in order to prevent our work space (workspace) on the hard drive suddenly hung up, but you do not worry about the entire hard drive is hung up. Of course, this is only a small probability event. More importantly: we need to work together to develop the same software in team development, it is impossible for me to write code copy to you, you write code copy to me, we need a unified remote version control warehouse: GitHub
Three. We started the GitHub tour. 1. First explain the meaning of several words (⊙o⊙) ...

It's going to be used later, and it's important:

    • Pull: Pulls
    • Push: Push
    • Repository: Warehouse
    • Branch: Branch
    • Status: State
    • Commit: Submit
    • Config: Configuration
    • Global: Globally (attributes, variables, etc.)
2. Draw a diagram to explain git local operations and the logical flow of remote operations

    • As you can see, our daily coding, first of all, the changes in the workspace of the code through the operation of ① to push to staging area (Index,stage), and if we confirm that the code is correct, without modification, then we can push it through ② to the local master branch, Here we can understand the master branch as a local temporary repository, we can recover the code from here, or we can submit it to the master branch on the remote github via this branch, and give your code to someone else.

    • We just described the process of moving from local to remote. Let's get this high first, and I'll do it again in the back.

3. We first implement step ①

1. If we make changes to the code, here we take a file Readme.txt as an example to explain. (That is, we now assume that the working interval is e://firstrep, there is a file readme.txt)
2. First we open D://firstrep, in this directory in the blank right click Open to Git Bash.exe, initialize a local repository.

[Email protected]/e/firstrep
$ git init
Initialized empty Git repository in e:/firstrep/.git/(master)

Note: Only start with "$" is the command we write, the other is the system automatically generated prompt information, which after the initialization of the command we can see the path name after a "master", which indicates that we initialize successfully.

3. Let's look at the workspace, repository, staging area, and local master branch

    • Working space: E:/firstrep

    • Repository: e:/firstrep/.git/(master) Note that the. git folder is hidden and invisible, and you can change the folder properties to make it appear.

    • Staging area and Master branches: These two things exist under the repository folder

4. We make changes to the file first:

Git is very easy.

We then submit it to the repository's staging area (Index,stage) and execute the following code to see the GIT status

$ git status
On Branch Master

Initial Commit

untracked files:
(use "git add ..." to include in what'll be committed)

   readme.txt

Nothing added to commits but untracked files present (use "Git >add" to track)

This will prompt us to say: There is one more file in the workspace, we have not added to the repository

5. Let's add it to the staging area in the repository.

Git add–all

In this way, our first ① link has been executed.

4. Let's proceed to step ②

1. We have just added the changed Readme.txt to staging Area (Index,stage) and now we add it to the local master branch.

$ git commit-m "test
[Master (root-commit) 74C27DF] Test
1 file changed, 1 insertion (+)
Create mode 100644 readme.txt

We are now going through the above line to tell Readme.txt to submit to the local Master branch (in fact, this is not very accurate, actually commits the modification, not the entire content, here we can first so simple to understand). Let's take a look at Git's status

$ git status
On Branch Master
Nothing-to-commit, working directory clean

OK, so far, we have successfully completed the local code submission. That is ①② two steps.

Let's proceed to the third part.

5. Perform step ③

Now it should be a remote with a branch, there is a branch locally, we create a warehouse on GitHub (repository). Suppose the warehouse address is: https://github.com/hellochillax/Yard.git

Below we push:

1. Add the address of the remote repository:

$ git Remote add Origin https://github.com/hellochillax/Yard.git

A correspondence is created here: origin–>https://github.com/hellochillax/yard.git

2. Push the operation:

$git Push Origin Master

Then you will be prompted to enter the GitHub account password, enter the correct account password, click Enter, the system will be submitted to work, and will show the progress. Of course, I do not show here, in case my original project is covered out. (The GitHub address above is a project on GitHub that I can't push ... Of course you see here also don't want to sabotage, because you do not know my GitHub account password ... )

All of our content above solves the local push to GitHub, and we're here to talk about pulling what was written from GitHub to the local repository.

6. Let's start with a picture, and there's a good saying, No.。 **

Below, we are still in three steps:

7. Perform step ①

With the above experience, we can be a little faster ~
On the command:

$ Git pull Origin Master

The above command is to pull the file from remote to local. (Again, I'm not going to give you a demonstration.

8. Perform step ②③

Before we do that, let's look at the status of git:

$ git status
On Branch Master
Nothing-to-commit, working directory clean

Yo yo yo, what situation, how is "nothing to commit", how to, should not be copied from the repository to the workspace, how can not be submitted it.

Don't worry, you open the working directory and find that all the files on GitHub already exist in the working directory. In other words, step ①, in fact, has helped us fix the ①②③ to do. So, the ②③ step actually doesn't want us to do anything.

Four. Git's use of the details supplement
    1. We have to develop a good habit, every night before the computer, remember to put their daytime code written to the GitHub, in case of their own fruit loss, although the odds are small, but this is a good habit. In particular, the repository on GitHub is public (free), meaning that if you don't want to expose your code, don't put it on GitHub, or spend money on a private warehouse.
    2. Git a lot of knowledge, the use of a lot of detail, I just put the two big process to say it again, in fact, Git is very powerful, there are many need to learn, such as multi-branch management, conflict resolution, Git and Eclipse or IntelliJ combination. But also follow the 28 principle, only 20% of the operation is we often use, so, if you see now feel difficult general, then you are very good, after all, my ability to express is not general-like ...
    3. Blog writing less, content is inevitably more inappropriate, but also hope that you criticize correct. Hope this blog will provide you with some help, this is my blog to write the purpose.
Five. Finally stick to the git common operation I usually summarize
  • Git init initializes a local repository

  • Git add–all Add all files to Staging area (Stage,index)

  • git commit-m "description information" Commit Changes to local master branch

  • Git status View git current state

  • git diff see what's different after the change and before the change

  • Git log gets the history of file changes

  • Git reset–hard head^ fallback local branch to previous version

  • Git reset–hard head~n fallback local branch to top N versions

  • Git checkout–readme.txt: Undo all changes to the Readme.txt file in the workspace

  • Git remote: Get a list of remotely-available libraries

  • Git remote RM [name]: delete the corresponding library
  • git remote add origin [email protected]/hellochillax/softwareyard.git associated with a remote library
  • Git push-u origin master pushes all the contents of the master branch for the first time
  • Git push origin master pushes the latest changes
  • git branch-u origin/master master local trace remote

    GIT encourages the use of branching:

    View branches: Git branch
    Create a branch: Git branch
    Switch branches: git checkout
    Create + Switch branch: Git checkout-b
    Merge a branch to the current branch: git merge
    Delete branch: Git branch-d

  • Ssh-keygen-t rsa-c "[email protected]" Create SSH Key

  • git config–global user.name "Your name" setting user name
  • git config–global user.email "[email protected]" setting password

Command line General operations:
PWD: Show current path
Ls-ah: Show file list (including hidden files)
Cat readme.txt: Displaying file contents
RM Readme.txt: Deleting files

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

git--team to develop the necessary artifacts

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.