This is important to understand - because Git submodules work differently! When new commits are made on this branch, the HEAD pointer is automatically moved to the very latest commit. By using git checkout or the newer git switch, we’re telling Git what our currently active branch should be. In a “normal” Git repository, we usually check out branches. Accordingly, we have to commit this change like any other: $ git commit -m "Add timezone converter library as a submodule" " to unstage )Īs you can see, Git regards adding a submodule as a change like any other. Let’s have a look at the status of our main project, now that we’ve added the submodule: $ git status Either use the proper Git commands or a desktop GUI for Git like “Tower”, which takes care of these details for you. That’s why it’s important to take one thing away: don’t mess with Git submodule configuration by hand! If you want to move, delete, or otherwise manipulate a submodule, please do yourself a favor and do not try this manually. However, it probably helps you to understand that the internal maintenance of Git submodules is quite complex. git/modules folder.Īll of these are technical details you don’t have to remember. git/config, which now ends like this: Īnd finally, Git also keeps a copy of each submodule’s. gitmodules file is one of multiple places where Git keeps track of the submodules in our project. gitmodules file has been created in the root folder of our main project. The submodule, however, makes sure that the library files don’t “leak” into our main project’s repository. The crucial difference is indeed that they are contained in their own Git repository! Had we just downloaded some files, thrown them into our project and then committed them - like the other files in our project - they would have been part of the same Git repository. After all, the third-party library’s files are here, just like they would be if we had copy-pasted them. “So what’s the difference?” you might ask. Resolving deltas: 100% ( 5159/5159 ), done.Īnd if we take a look at our working copy folder, we can see that the library files have in fact arrived in our project. When we run this command, Git starts cloning the repository into our project, as a submodule: Cloning into 'carparts-website/lib/spacetime'. Let’s say we need a little “timezone converter” JavaScript library: $ git submodule add Now we’re ready to pump some third-party code into our project - but in an orderly fashion, using submodules. Before we go get any code, it makes sense to create a separate folder where things like these can have a home: $ mkdir lib Let’s take the classic example and say we’d like to add a third-party library to our project. Maybe you just want to share your own code between two projects - a situation where submodules might offer the simplest possible workflow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |