Git is an open source distributed version control system that can efficiently and rapidly handle project versioning from very small to very large.
This article takes the example of using Git to upload a local project to GitHub, providing a way for those newcomers to git to upload a local project to the github/coding/code cloud using Git.
Sign up for a GitHub account and install Git
- Start by registering your GitHub account and adding new items.
- Download and install git, the installation path can be modified by itself, some settings during the installation select the default.
Use Git to upload local projects to GitHub
- In the local project folder, right-click to select "Git Bash here"
- Git Global Settings
$ git config --global user.name "user.name"$ git config --global user.email "user.email"
- Initializing the Git repository
$ git init
$ git add .
Note the following "." Don't forget to write. If you want to sync only one file, you can change the "." To the "file name" that you want to sync. Such as:
$ git add README.md
$ git commit -m "注释内容"
- Establish an association with a remote github repository
The remote warehouse address is the new project address that you just added on GitHub https://github.com/user name/project name. Git
$ git remote add origin https://github.com/用户名/项目名.git
- Sync to a branch of a new project in remote GitHub (default is General Master)
$ git pull origin master
- Upload Warehouse to GitHub
$ git push origin master
If the following error occurs:
[Rejected] master, master (Non-fast-forward)
The reason is that there is already a part of the code in the remote GitHub repository, so it doesn't allow you to overwrite your code directly. There are 2 workarounds:
1. Force overwrite, that is, force your local code to replace the content in the remote GitHub repository:
$ git push --force origin master
2. First fetch the contents of the remote GitHub repository to local and then merge and push
$ git fetch$ git merge$ git push origin master
- Refresh GitHub page and OK.
Use Git to upload local projects to github/coding/code cloud