Before submitting the contents of the local git warehouse to the GitHub warehouse, you need to create a Repository with the same name on GitHub ( refer to git&github self-study tutorial (2): register and configure github information, and get a preliminary understanding of the interaction process between git and github ). Do not automatically generate README.md to avoid conflicts with local warehouses.
1. Push to the GitHub repository
1, git remote add-add remote warehouse
The path of the warehouse just created on GitHub is "[email protected]:xiaolu2333/git-tutorial.git". Now use the git remote add command to set it as a remote warehouse of the local warehouse :
Git will automatically set the name of the [email protected]:xiaolu2333/git-tutorial.git remote warehouse to origin, which is the local alias of the remote warehouse. It can be deleted using git remote prune origin.
2. git push-push to remote warehouse
1. Push to the master branch
The content of the current branch will be pushed to the master branch of the remote warehouse origin: The
-u parameter can set the master branch of the origin warehouse to the upstream (upstream) of the current branch of the local warehouse while pushing. With this parameter added, when you run the git pull command to get content from the remote warehouse in the future, this branch of the local warehouse can directly get the content from the master branch of origin, saving the trouble of adding additional parameters.
The specific parameters can be viewed through "git --help command name".
2. Push to a branch other than master. It
can be seen that the remote warehouse can also create a branch, that is, we can push a local branch to a branch of the remote warehouse:
2. Obtain from remote warehouse
Earlier we pushed the master and a feature-D.
Anyone who can access this remote repository can get the feature-D branch and modify it. Now we will simulate a new developer to jointly develop the project just now.
1. Get remote warehouse
First we need to switch the working directory to another file:
then clone the project:
enter the project directory, the default is to be in the master branch:
2. Get the remote feature-D branch
View all branches:
get the feature-D branch to the local warehouse:
3. Submit changes to the local feature-D branch
4. Push feature-D branch
Clone Warehouse ""Get Branch" "Development"" Push.
Three, git pull-pull the latest remote warehouse branch
As the initial pusher of the project, the D branch after the push did not do anything. Now there are other people developing in the D branch. If we need it, we must pull the latest D branch.
First switch back to the original working directory:
we are still in the D branch, and use the git pull command to update the local feature-D branch to the latest state: in the
future, we only need to commit locally and push to the remote warehouse as usual, and then we can communicate with Other developers are working on the same branch at the same time, constantly adding new features to feature-D.
If two people modify the same part of the source code at the same time, conflicts will easily occur during push. Therefore, when multiple developers are working on the same branch, in order to reduce the occurrence of conflicts, it is recommended to perform push and pull operations more frequently.