Git is an open source distributed version control system for efficient, high-speed processing of project versioning from very small to very large.
Install Git
1. Method One:
Install homebrew, and then homebrew
install Git.
First step: Install the following command in the terminalhomebrew
1
|
"$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
Step Two: Execute the following command to install Git via homebrew.
Refer homebrew
to the documentation for specific methods: http://brew.sh/
Homebrew is developed in the Ruby language to support the deployment and management of thousands of open source software in Mac OS x.
2. Method Two:
Just go to the GIT website and download it. http://git-scm.com/downloads/
Using Git
You typically use Git to create a repository, or a repository.
The first step: Create a directory in the right place.
1 2 3
|
mkdir Firstgit
CD Firstgit
|
Step two: Use the git init
command to turn this directory into a repository that can be managed using Git.
1 2
|
$ git init /users/dahuan/desktop/multithreadingdemo/.git/
|
Execution ls -a
discovers multiple files in the directory .git
, and this is the file that Git uses to track management.
Step three: Create a file in this directory and enter some content.
Fourth step: Tell git with the command to git add
add the file to the repository
If you want to add too many files, you can write Git add-a
Fifth Step: git commit
submit the file to the warehouse with the command
At this point we have successfully added and submitted a Readme.txt file to the local repository.
Submit a local warehouse to the remote repository github
You can build a server that runs git on your own, but at this stage, it's definitely a fuss to learn to git a server first. Fortunately, this world has a fantastic website called GitHub, from the name can be seen, this site is to provide git warehouse hosting services, so as long as you register a github account, you can get free git Remote Storage.
Please register your GitHub account before continuing to read the following. Because the transfer between your local git repository and the GitHub repository is encrypted via SSH, a bit of setup is required:
Create an SSH Key. In the user home directory, see if there is no. ssh directory, if there is, then look at this directory there are no Id_rsa and id_rsa.pub these two files, if already have, can jump directly to the next step. If not, open the shell (open git Bash under Windows) and create SSH Key:
1
|
ssh-keygen-t RSA-"[Email protected]"
|
View your Public key
Login to GitHub, open "account Settings", then, click "Add SSH Key", fill in any title, paste the contents of the Id_rsa.pub file in the Key text box. Click "Add Key" and you should see the Key already added. In order to verify success.
1
|
$ 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.
1 2
|
$ git config--global user"your name" $ git config--global user"[Email protected]"
|
Why does GitHub need SSH key? Because GitHub needs to recognize that your push submission is actually pushed by you, not someone else impersonating it, and Git supports the SSH protocol, so if GitHub knows your public key, you can confirm that only you can push it.
Log on to GitHub and then, in the upper right corner, find the "Create a new Repo" button to create a new warehouse.
In Repository name fill in the Firstgit, the other remains the default settings, click the "Create Repository" button, the successful creation of a new Git repository.
Now, let's run the command under the local Firstgit repository, based on GitHub's prompt:
1
|
$ git Remote add origin git@github. xxxx/xxxx.git
|
Origin is the default host name
[Email protected]/xxxx.git is URL
This allows us to set up a remote host on the local. Git.
We use the following command to push the local repository to the remote repository:
A tutorial on using Git