If you have nothing to worry about in the evening, continue to toss github. This time, we will mainly talk about how to create a local git repository and synchronize the remote git repository and git branch.
First, create a project. Before creating a project, we need to do two things:
- Create a repository on GitHub. you can log on to github.com or complete the repository on GitHub for Windows. After the repository is created, GitHub automatically initializes the project (GIT init)
- Open git bash and clone the GitHub project to your local directory.
1 yourname@yourname-PC /path/to2 $ git clone git://github.com/youremail/project.git3 Cloning into 'project'...4 remote: Counting objects: 3, done.5 remote: Compressing objects: 100% (2/2), done.6 Receiving objects: 100% (3/3), done.7 remote: Total 3 (delta 0), reused 0 (delta 0)8 yourname@yourname-PC /path/to9 $
In this way, a local repository is created.
After creating a repository, We will modify the project, for example, creating a file named example. js. Create a new example. js file manually, and submit the changes to the local repository.
1 yourname@yourname-PC /path/to 2 $ cd project 3 yourname@yourname-PC /path/to/project (master) 4 $ git add example.js 5 yourname@yourname-PC /path/to/project (master) 6 $ git commit -a -m 'create example.js' 7 [master c0cb8b9] create example.js 8 1 file changed, 0 insertions(+), 0 deletions(-) 9 create mode 100644 example.js10 yourname@yourname-PC /path/to/project (master)
Git addAdd the created file informationGitIn the index library, that is, after creating a new fileGit addTo add the file to the repository (but this modification is not submitted ).
Git commitCommand Parameters-Indicates that all modifications are submitted (All),-MAdd comment information (Message)
Of course, only the modifications are submitted to the local repository and not synchronized to the remote server repository. The modifications submitted locally are synchronized to the remote repository.
1 yourname@yourname-PC /path/to/project (master) 2 $ git remote add origin git@github.com:youremail/project.git 3 yourname@yourname-PC /path/to/project (master) 4 $ git push origin master 5 Counting objects: 4, done. 6 Delta compression using up to 4 threads. 7 Compressing objects: 100% (2/2), done. 8 Writing objects: 100% (3/3), 277 bytes, done. 9 Total 3 (delta 0), reused 0 (delta 0)10 To git@github.com:youremail/project.git11 fbf0eb6..c0cb8b9 master -> master12 yourname@yourname-PC /path/to/project (master)
$ Git remote add is to specify an alias for the repository on github, where the git@github.com: youremail/project. git is designated as the alias of an origin, which saves the trouble of inputting a long string of repository names for push and other operations.
So far, we have finishedProject Creation-> local modification-> Local submission-> synchronize to GitHub.
We can see the 11th rows aboveMaster> masterHere, the master represents the github project branch. For the project branch, we can understand this. For example, a project has two branches: master and secondary, the two branches are equivalent to the two parallel versions of this project. Before merge (merge), the two branches do not affect each other. modifications submitted in secondary will not affect the projects in the master branch, that is to say, if we suddenly want to experiment with an idea during the development project, but we are worried that it will affect the main body of the project, we can create a branch) if this idea has been tested in practice, we can also merge it into the master branch.SecondaryBranch changes will be synchronizedMasterBranch, your idea will be applied to the project.
For a branch, run the following command:
1 yourname@yourname-PC /path/to/project (master)2 $ git branch secondary3 yourname@yourname-PC /path/to/project (master)4 $ git checkout secondary5 Switched to branch 'secondary'6 yourname@yourname-PC /path/to/project (secondary)7 $
Git BranchIs to create a local branch,Git checkoutSwitch to another branch.MasterBranch switchedSecondaryBranch.SecondaryThe changes on the branch are submitted locally and synchronized to the remote git server.
1 yourname@yourname-PC /path/to/project (secondary) 2 $ git push origin secondary 3 Counting objects: 3, done. 4 Delta compression using up to 4 threads. 5 Compressing objects: 100% (2/2), done. 6 Writing objects: 100% (2/2), 297 bytes, done. 7 Total 2 (delta 0), reused 0 (delta 0) 8 To git@github.com:youremail/project.git 9 c0cb8b9..27c5c5d secondary -> secondary10 yourname@yourname-PC /path/to/project (secondary)11 $
HereOrigin isPreviously UsedGit remote addThe repository alias.
Git pushSynchronize local modifications to a remote device.GitOn the server, the modifications submitted by the branch are also synchronized to the corresponding branch.
Conclusion: The above is what we are doingGitSome common operations for Distributed warehouse project development are in use, of course.Git bashWe may encounter some errors more or less. Read the error information carefully and find many errors because of the presetOrigin-- The repository alias cannot be used for certain operations,Git bashIt will also prompt you to use another path for submission, which may beGitProtocols andSSHThe Protocol application scenario is different.