Getting Started with Git
If you have no access to git at all, you can now simply understand the syntax of git (typing some commands) to upload the code to a remote repository or download to a local repository (server), we should have two warehouses at this time, that is, two places to put code, one is local, and the other is remote ( such as GitHub). The enterprise or team can manage the project through Git, and each programmer simply uploads the code written by his local repository to the remote repository, and another programmer can download it to the local repository. Today we start with the installation of Git terminal software, and before that I'll briefly introduce GitHub.
What is GitHub?
The GitHub site is a remote repository where we can upload programs to their sites, and GitHub is currently a very large code-hosting repository. The website is https://github.com you can register an account with the website in advance, etc. will be used.
git terminal Software Installation
1, download Git terminal on Windows, similar Shell tool,: http://msysgit.github.io/
2, installation method, open the file, all the way click Next can
3, the installation is complete, the interface is as follows
Create a warehouse locally
Note: Each git statement starts with $ (the terminal is usually automatically added), #后面代表注释, enter the Run command
1. Create an identity (change oldinaction and [email protected] to your own username and email)
git config--global user.name oldinaction #用户名
git config--global user.email [email protected] #邮箱
2, select a disk under window to build a git repository directory (after running the following two sentences will automatically create a mygit directory on the computer H disk as a git local repository)
cd/h
mkdir Mygit
3. Create your own project folder name
mkdir Demo #创建的项目文件名叫Demo
CD Demo #进入到Demo目录
4. Initialize the Git repository (after this step is completed, a hidden. Git suffix file is generated)
Git init (git add file with this error: Fatal:not a git repository (or any of the parent directories):. Git hints that there is no. git such a Directory, the workaround is as follows: then enter GIT init directly on the next line! )
5, submit the content to the warehouse, copy our project files to the H:/mygit/demo directory
git add test.html #只提交当前目录的test. html file to the local git repository (although the file is in this directory, but if it is not committed, it is not in the local git repository and then cannot interact with the remote repository)
git add . #就可以把所有内容添加到索引库中, notice there's a point in the back.
git commit-m "comment content" #提交索引库中的内容;-M is a parameter that represents the comment content, mainly used to record this operation
Use Git to upload your project to GitHub
1. Register your GitHub account
2, new project, click the link in the image below
3, fill in the project information, such as ( where "Initialize this repository with a README" for this project to add a description file, tick also hurt )
4. Generate a public key file in git to connect to GitHub. in the GIT command console, enter the following command, 3 consecutive enter can be hit
Ssh-keygen-t rsa-c "[email protected]" #改成你的邮箱
5. After the command is generated, you can find the public key file (id_rsa.pub) in the C:\Users\qindongliang\. SSH folder#注意命名和文件路径
6, in order to prevent the link git failed, you can create a new suffix name of the config file, add the following code inside
Host github.com User git Hostname ssh.github.com preferredauthentications publickey identityfile ~/ . Ssh/id_rsa
7, in the GitHub account settings ssh keys, see, where title own name, key content is to copy the code in the Id_rsa.pub all over
8. Test the link GitHub on the Git terminal
ssh–t [email protected]
If you are prompted for an error similar to ssh:could not resolve hostname \342\200\223t:name or service not known, the workaround is to execute the following command: SSH-T-p [email protecte D] #-p means modify the server port to 22 when prompted for input (yes/no)? Enter Yes at the back
When you see the Welcome Hi oldinaction! You've successfully authenticated, but GitHub does not provide shell access. The link is successful.
9. Upload code to remote repository in local warehouse
(1) Go to the local warehouse:
- In Git, use "CD directory name" to enter our repository under the demo root directory
- Or go directly to the demo root directory, right-click, you will find that the Git terminal to our right button binding a "Git Bash here", click on the master to enter the local repository, and open the Git terminal
(2) Run the following code
git remote add origin [email protected]:oldinaction/demo.git #其中 [email protected]:oldinaction/ Demo.git is the SSH address of our demo project in GitHub #github上的上传路径
Git push-u origin master #推送 upload
(3) If there is a non-fast-forward error, this is basically a git repository already has a part of the code, so it does not allow you to directly overwrite your code. There may be people in the new project configuration project information, the new Readme file option is ticked. Workaround:
git push--all-f #强推 to replace content in Git repositories with your local code using overrides
10. Go to the GitHub Project homepage Https://github.com/oldinaction/demo to see the code uploaded from the local repository to the GitHub remote repository
Githe and GitHub Connect, upload