![]() ![]() You do not need to call this if you added the submodule through submodule add.Does initial setup on submodules that have been pulled or cloned.If you wanted to clone, then you must delete the directory first If already exists, then it must already be a git repository.Same as git submodule add, but you can specify where the submodule is to live.can be a local file path, or a web url.Clones out the git repository from (as if you had called clone ) and tracks it as a submodule.Here is a quick recap of all the git commands that were used here: git submodule add In other words, use checkout master (or the branch of your choosing) to reground yourself to a branch. If you’re not very familiar with how to escape the state, just remember: the detatched head means you’re not really following a branch in the traditional sense, so you want to do that first. Detatched HeadsĪ quick word about beheadings, because you will see them a lot with submodules. Other NotesĪ few other brief notes that might be useful if you start working with submodules. The next step is the same: add, commit, and push. Hopefully that looks familiar, because it’s the same thing you would have seen if you checked the status in Example 5.3. Modified: Assets/Plugins/BGC_Tools (new commits ) Tstavrop:~/PART/Assets/Plugins/BGC_Tools $ cd ~/PART Tstavrop:~/PART/Assets/Plugins/BGC_Tools $ git pull Example 5.2: Pushing changes to a submoduleĬontinuing example 5.1 above, you just need to add, commit, and push your changes in the submodule first… Remember, the repository only tracks the submodule by its current commit, so you can’t push repository changes and keep submodule changes that weren’t committed, and if you don’t push your submodule commits, then you’ll be able to use them locally, but nobody else will. If you wish to keep changes that you’ve made in a submodule and use them in the parent module, you must first commit and push the submodule changes first. No changes added to commit (use "git add" and/or "git commit -a" ) Making Changes " to discard changes in working directory ) " to update what will be committed ) (use "git checkout. Your branch is up to date with 'origin/master'. Tstavrop:~/PART/Assets/Plugins/BGC_Tools $ git status Tstavrop:~/PART $ cd Assets/Plugins/BGC_Tools " to discard changes in working directory ) (commit or discard the untracked or modified content in submodules ) ![]() Your branch is up to date with 'origin/dev'. Navigate to where you want the submodule and submodule add it. Example 1.1: Adding a submodule to a repository Let’s take a look at how you can add an existing repository ( BGC_Tools) as a submodule to a different existing repository ( PART). In the examples below, PART is a Unity project and git repository located in ~/PART/, and BGC_Tools is a submodule from our real, open-source repo of Unity tools. They show how easy managing a submodule is (if you use git from command-line, which I highly recommend all programmers be comfortable with). Real Life Examplesīelow are some command-line examples showing working with Submodules. So if you make some breaking changes in GameEngine, you can wait to pull those changes into a project until you’re ready (if ever). If submodules didn’t work this way, they really would be unusable. So, what happens if someone pushes new commits to the GameEngine repository and you use git pull in your Game repository? Nothing happens. When you add a submodule inside a project, you actually just tell the project’s repository to checkout a specific commit of the submodule repo. Git submodules work in a quintessentially git way (I’m saying that as a good thing). To use an example out of game development, code representing your core game engine would live in the GameEngine repository, and all of your games built using it would have their own repositories and include GameEngine as a submodule. Using a submodule is really just telling one git repo “keep this whole other repo here inside you, and don’t manage its files”. ![]() If you have different projects that share any nontrivial amount of common code, especially code like generic tools and utilities, and you use git for source control you should look into a git submodule to share said common code. Example 6: Pulling new submodule commits into a repository.Example 5.3: Pushing submodule updates to a repository.Example 5.2: Pushing changes to a submodule.Example 5.1: The project and the submodule have changes.Example 4: The project and the submodule are up to date.Example 3: Pulling changes that update the submodule.Example 2: Pulling in the addition of a submodule.Example 1.2: Adding a submodule using an existing git repository.Example 1.1: Adding a submodule to a repository. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |