Version control of individual files using GitHub Gist
It often happens that a developer with-time accumulates some collection of code that he uses in his projects.
He uses some scripts in some projects, others in others.
These scripts are improved over time, bugs are removed, optimized. Therefore, the question arises how to synchronize new versions of scripts with those that are in projects .
There are several options:
Create one repository and put all the scripts there. Then this repository is connected as a sub-module to the project and used.
- All scripts including unnecessary ones are copied to the project.
- the submodule is not commit to the project repository, so if the remote repository of the submodule is unavailable, then we will not be able to deflate the entire project.
Store each script separately on Github gist and connect the necessary as submodules
Minus the same as in the first option in the second paragraph.
The third option:
Use Git Subtree.
(This solution is an alternative to Git submodules)
Git subtree is another method of merging branches. His idea is that having two branches, git will understand that one branch is not a variation of the other, but an addition.
The general essence of the idea:
- - add the file to Github gist (a mini-repository is generated)
- - we bind a mini-repository to our project as a separate branch
- - assign folder for this branch
- - pumped out.
- - further we work as with a normal branch (merge, commit, fetch ...)
Now for details using Git-extensions.
1) We publish our code file at https://gist.github.com where we can immediately get a link to the “mini” repository:
Open the repository of our project in GitExtensions and select:
[Repository] -> [Remote repositories ...]
We connect as a separate branch.
To do this, press [+] . Enter [Name] , [Url] and save [Save changes] :
$git remote add"Util1""https://gist.github.com/cf056e792d3bd9c2fc5973b846efe3d3.git"
We see that connected to a remote repository.
Next, we need to associate this thread with a specific folder in our project so that the file is copied there.
To do this, open Git-bash (ctrl + G) and execute the command:
$git read-tree --prefix=Client/Assets/ -u Util1/master
Client / Assets / is the path to the folder to which the
Util1 / master file will be copied — the name of the remote repository branch
(via UI did not find the way) The
gist branch becomes attached to our folder in the project. And the file is already there.
Now we can work as with a normal branch.
For example, if the file in the Gist changes, we can get a new version:
Make Fetch All and see all the changes:
$git fetch --progress "--all"
Then we merge to upload changes to our thread:
$git merge -s subtree --no-ff --allow-unrelated-histories Util1/master
subtrees https://www.atlassian.com/blog/git/alternatives-to-git-submodule- git-subtree