Version control of individual files using GitHub Gist

Version control of individual files using GitHub Gist
 
 
It often happens that the developer is accumulating a certain collection of code with time, which he uses in his projects.
 
 
He uses some scripts in some projects, others in others.
 
 
These scripts are improved with time, bugs are cleaned, optimized. Therefore the question arises, How to synchronize new versions of scripts with those that are in projects .
 
 
There are several options:
 
 
The first variant:
 
 
Create one repository and put all the scripts there. Then this repository is connected as a submodule to the project and is used.
 
 
Cons:
 
 
 
The project copies all scripts including unnecessary ones.
 
the submodule is not committed to the project repository, so if the remote repository of the submodule is unavailable, we will not be able to download the entire project.
 
 
The second option:
 
 
Each script is separately stored on the Github gist and connected as needed as submodules
 
The downside is 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)
 
https://gist.github.com where immediately we can 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 store [Save changes] :
 
 
$ git remote add "Util1" "https://gist.github.com/cf056e792d3bd9c2fc5973b846efe3d3.git"
 

 

 
We see that we connected to a remote repository.
 

 
Next, we need to associate this branch 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    

 
where:
 

 
Client /Assets / - the path to the folder into which the
file will be copied.  
Util1 /master - The name of the branch of the remote repository
 
(through UI did not find a way)
 

 
The Gist-branch becomes bound to our folder in the project. And the file is already there.
 

 
Now we can work as a normal branch.
 

 
For example, if the file changes in the Gist, we can get the new version:
 

 
We do Fetch All and see all the changes:
 

 
    $ git fetch --progress "--all"    

 
Then we merge to fill the changes in our branch:
 

 
    $ git merge --no-ff --allow-unrelated-histories Util1 /master  
 

 
 

 
 
Result:
 
 

 
 
Additional information:
 
 
https://git-scm.com/book/ru/v1/Tools -Git-Merging-subtrees
 
https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree
 
https://www.nwcadence.com/blog/git-subtrees
+ 0 -

Add comment