Git uploads code to remote repositories and clones from remote libraries

Source: Internet
Author: User
Tags commit reset using git git clone

1. Download and install Git

Download: https://git-scm.com/downloads

Installation: Refer to article http://blog.csdn.net/zzfenglin/article/details/53147604

First, create a version library

1. Open git input command and switch to local repository directory


2. By ordering git init to turn this directory into a repository that git can manage, as follows:


3. Create a new Notepad file in the local directory Readme.txt content is as follows: This is a test (can be written freely);

4. Execute the git Add file name command at the command line to add the file to staging area, without any hints indicating success, as shown in figure:


5. Execute git commit-m ' commit comment ' on the command line and submit the file to the repository.


6, the following can be ordered by the GIT status to see if there are still files not submitted, as follows:


7, modify the next Readme.txt content, such as adding a line of 2222222222 content, continue to use Git status to view the results, as follows: The following figure shows the Readme.txt file has been modified, but not committed changes.


8. Execute the git diff file name command at the command line to see what the Readme.txt file has changed, as shown in figure:


9, submit the changes. Commit to modify and submit the file is the same as 2 steps (the first step is the git add filename, the second step is: Git commit-m ' comment '). As shown in figure:


Second, version return

1, now I continue to modify the Readme.txt file, and then add a line of content of 33333333333333. Continue to execute the command as follows:


2. Execute git log command downstream to view history


3, now I want to use the version fallback operation, want to fallback the current version to the previous version, the command line execution git reset--hard head^ (head^ represents the previous version)

Before returning, use the instruction cat file name to view the contents of the Readme.txt file, before exiting, the content is as follows:


After executing the git reset--hard head^ command at the command line, the version is returned to the previous version, and the contents are read again as follows:


4, there is recall recovery, the first can be obtained by command git reflog version number, and then by the command git reset--hard version number can be restored. As shown in figure:



Iii. Understanding the work area and staging area

Workspace: The directory you see on your computer, such as the files in Testgit (except the. git hidden directory repository). or later, you need to create a new directory file, and so on is the workspace category.
Repository (Repository): The workspace has a hidden directory. Git, this does not belong to the workspace, this is the repository. The repository contains a lot of things, the most important of which is the stage (staging area), and Git automatically created the first branch master for us, and a pointer to master head.
As mentioned earlier, there are two steps to submitting a file to the repository using git:
The first step is to add the file using git add, which is actually adding the file to the staging area.
The second step: Commit the change using git commit, which is actually committing all the contents of staging area to the current branch.

1, in the Readme.txt add a line of content of 4444444, and then first use the command git status to view the status, as shown in the figure shows that the modified content is still working to not add to the staging area:


2. Execute the git add command at the command line to add the modified file to staging area as shown:


Iv. Remote Warehouses

1. Add Remote library

1) Register your account password on the GitHub website and build a new library in the Git repository, as shown below:


2) Enter the warehouse name in Repository name, the other remains the default setting, click the "Create Repository" button to successfully create a new git repository. The following figure:


At the moment, this testgit warehouse on GitHub is still empty, and GitHub tells us that we can clone a new repository from this repository, or associate an existing local repository with it, and then push the contents of the local repository to the GitHub repository.


3) Run command in local repository git remote Add Origin remote warehouse address associate the local repository with the remote repository, then execute the GIT push Origin master to synchronize the master branch of the local library to the remote repository, and then enter the user name and password as prompted As shown in figure:


Since the remote library is empty, and when we first push the master branch, with the –u parameter, GIT will not only push the local master branch content to the remote new Master branch, but also associate the local master branch with the remote Master branch. You can simplify the command at a later push or pull. After the push is successful, you can see the remote library's content in the GitHub page immediately as if it were local. As shown in figure:


From now on, as long as the local commit, you can use the command: Git push origin master to push the latest changes to the local master branch to GitHub

2. Cloning from remote library

1) at the command line switch to the file directory where you want to store the repository, then execute the GIT clone remote Warehouse address command, as shown in figure:

2) After cloning is complete, local can see the repository from the remote clone as shown below:


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.