First, git and github brief
1.Git
The distributed version control system, first used in the Linux community, is an open source, free version control system that functions like SVN and CVS. The biggest difference between git and other version management tools is distributed;
Git uses a distributed repository mechanism that does not need to push files to a version control server every time, and each developer can clone a full repository from the server to the local without relying entirely on the version control server. "Pros: 1. Code publishing and merging is more convenient; 2. You can make file submissions offline, create branches, and view historical version information, among other things"
Git also outperforms other version control tools in the form of file saving. The previous version control tool saved the differences between versions, and Git focused on the overall changes in file data, directly producing snapshots of the data at the time the file was submitted, and using the SHA-1 encryption algorithm to ensure the integrity of the data.
2.GitHub
GitHub is a git-based project hosting platform, an open Web site. The repository we built locally using Git is a local repository, and GitHub is a remote repository, and a public repository where you can just register a github account to create a project repository on the platform. The project can be managed locally through a git visualizer or command line, making it easy to collaborate with others.
Second, git download and installation
1.Git: https://git-scm.com/download/
According to your own system to download the corresponding version, then the software installation, remember the installation address of the software.
2. After the software installation is successful, the right mouse click will appear "Git GUI Here" "Git Visual Interface" and "Git Bash here" git command operation interface.
Third, GIT environment configuration
You need to configure the environment before using git, or you will get an error when the push code goes to GitHub. GIT provides a tool called Git config that is designed to configure or read the appropriate work environment variables.
Configuration of user Information
1. Click Git Bash here to enter the command window settings:
2. Configure individual user names and e-mail addresses, and view configuration information
$ git config--global user.name "Here's your name."
$ git config--global www.yongshiyule178.com/user.email "Here's your mailbox"
$ git config--list
Write a picture description here
Four, Android studio hand git
Many of the next operations, such as building a local repository, adding files, submitting files, and pushing files to GitHub can all be done using the command line and the Git view interface, but this time only describes how the as is implemented.
1. Configuring Git in AS
(1) Use Ctrl+alt+s shortcut key to enter as setting interface;
(2) Select version Control and click Git to configure git:
Write a picture description here
"The path here has automatically acquired the GIT installation address, and if it's not populated, we're going to choose the git installation path."
(3) Click Test to see if Git is configured successfully, the following results indicate a successful configuration:
Write a picture description here
2. Configuring GitHub in AS
You must have a GitHub account before you can configure GitHub to register your account with github.com.
(1) Select version Control in the setup interface of AS and click GitHub to configure GitHub;
(2) Host:github.com is the default, Auth Type:password Select password Mode login
Login and password are GitHub's account and password, click Test to see if GitHub is successful, and the password may be verified again;
(3) If the Popup Success dialog box indicates a successful connection to GitHub.
Write a picture description here
3. Create a local warehouse for the project in as
Svn,cvs and other version management tools are the file resources and repository on the server side, if you need a version of the update and the comparison of the code needs to connect to the server. Git can create a local repository, however, and we can do the code locally and compare it to the previous version. How this is accomplished is done by building a local git repository. Here's how to build a git local repository for the current project or other folder in as.
How to create the current project in as as a local warehouse
1. On the toolbar, click VCs, select "Import into Version control" and then select "Create Git Repository" by importing the project into the versioning system.
Write a picture description here
2. Select the project or folder where you want to create the Git repository and click OK to complete the creation.
Write a picture description here
3. The success of creating a GIT repository flag is to create a. git folder at the root of the specified file. This folder is a hidden folder, and some systems do not show hidden folders by default. Find a way to display hidden folders in the corresponding system, showing hidden files to see. git files.
Write a picture description here
4.WIN10 System Open Hidden folder method "I use the WIN10, but also encountered a. git file can not see the situation, after several attempts to find that the problem is hidden folder is not displayed. 】
Open "My Computer", select "View" at the top, and click on the "Hidden Items" dialog box in the picture where red marks are selected.
Write a picture description here
5. After the new local Git repository succeeds, the file name in the project changes from white to red, indicating that the files have not been added to the hold area. Except for files registered in Gitignore. Gitignore as the name implies is to ignore the documents, about Gitignore will be explained in detail later.
Here write the picture description here to write a picture description.
4. Perform some git operations on the file in as
The basic use of Git is add to the suspend zone, commit to the local repository, push to the remote repository. We'll explain in detail next.
After the success of the Git repository, select the project or the file of the right mouse click, will display the "Git" function item, click "Git" to see the Git menu bar, here we first look at "Commit Directory" and "+add".
Write a picture description here
1. Add files to the "+add" zone
(1) Select the entire project or some files in the project, click "+add" to add the file to the hold area. After the addition succeeds, the file name changes from red to green, indicating that no commits have been added. Such as
Write a picture description here
(2) New file is added automatically. As mentioned above, the existing file is added to the hold area, it is not necessary to create a new file, of course, if you like trouble, the road can still make sense. If the project has been created successfully in a git repository, when you create a new file, as will prompt you to automatically add to the Git suspend zone. For example, we certainly choose to automatically add and use no reminders.
Write a picture description here
2.commit to local Warehouse
Click Commit www.xingchexiu.com diretory to enter the commit change view. In the picture, I describe the elements in the view.
Write a picture description here
Commit Message: This is the same as other versions of the tool to submit the code, introduce the change point
Before commit: Some of the actions that are committed in the code
Reformat code: Reformatting codes
Rearrange code: Re-organize the codes
Optimize Imports: Optimizing Import Packages
Perform Code Analysis: Performing the profiling [default selection], parsing before the code is submitted, and prompting if there is an error or warning
Check TODO (Show All): detects code that needs to be modified [show all default selections], that is, check the code for//todo, and if present, prompt
Clean up: Clears all
Update Copyright: Updating copyrights
There are also three ways of submitting:
Commit: Commit directly to the local repository
Commit and Push: Commit to the local repository and commit to the remote repository
Create Patch: Creating a git patch
(2) There are several ways to enter the commit view
-Use shortcut keys Ctrl+k
-click on the As top toolbar VCs submit button "Mark Red";
-Write a picture description here
(3) In general, we directly click on the commit, the file name from green to White after the successful submission. If we change the file contents, the filename will be changed from white to blue, such as:
Write a picture description here
3.Push to remote Warehouse
To push the project to the remote repository, we must first have a remote repository. We can register GitHub or Oschina to create a remote repository on top. Here we choose the International platform GitHub.
(1) Create a warehouse
Write a picture description here
Repository Name: Remote Warehouse Name
Description: Description
Public/private: Whether the project is open
Add. Gitignore: Create a. gitignore file "Select default, create an empty file"
ADD A license: Create an Authentication "default is OK"
(2) Following the successful creation of the warehouse:
The GIT address for the remote repository is behind SSH, which is used below.
Write a picture description here
(3) There are several ways to enter push:
After the remote repository is established, we start the push project, remembering that we have a commit and push option when we commit, which is a way to get into the push view;
At first we mentioned the Git menu, open the bottom of the repository, you can see some operations on the warehouse, where push is the push portal;
Write a picture description here
Using shortcut keys ctrl+shift+k into git view
(4) Git view
Write a picture description here
If you do not define a remote warehouse address, the name and URL of the remote repository is set through define www.xingchexiu.com remotes, which is the warehouse name and remote address when we created the GitHub warehouse.
(5) Push success can see uploaded items on github
Write a picture description here
To this end, you have successfully completed creating the local warehouse in as, adding the file to the hold, submitting the file to the local repository, and pushing the file to GitHub. In the next article we will continue to introduce as and git, such as how we pull files from GitHub to local, clone remote git, git create branch, git code compare and merge, Git. gitinogre files, etc.
Git and GitHub use in Android Studio