Using Git Offline - James Gibbard's Workshop

You might also like

Download as pdf
Download as pdf
You are on page 1of 6
41302019 Using Gt oftne - James Gibbard's Workshop Using Git Offline 88 2017-12-03 (hetpsi/wwwgibbard.me/using-git-offline/) & James Gibbard (https:/www.gibbard.me/author/james-gibbard/) @& Computers (https://www gibbard.me/category/computers/) Some companies use an isolated network or even the complete lack of a network as a security measure to protect from unauthorized access. Working on these systems can be a struggle but itis still possible, and perhaps even more important, to use a proper version control tool like Git. vogrant@virtuakipythonlasing fine - 2 x By design Git works quite happily with no remote repository. You can branch, stage, and commit files Just like normal nkdir testRepo cd testRepo git init touch test.txt git add --all git conmit -m "Initial Commit” This works great if just a single machine is used for development, but this is often not the case. Working with multiple machines —Using a USB memory stick/HDD When security policy allows read/write access to a memory stick or portable hard drive a remote repository can be created on this device. On one development machine mount the memory stick. cd /path/to/menory/stick kdir repoNane.git cd repoNane.git git init --bare tps hwo gidbare melusing-gt-ffine! 48 419072019 Using Gt ofting- James Gibbare's Workshop Navigate to the repository that is to be shared, add the remote repository on the memory stick, and push the changes. cd /path/to/local/repo/ git renote add origin /path/to/menory/stick/repoNane. git git push origin master NB. The remote can be called anything, It doesn't have to be called “origin” Unmount the memory stick and mount it on another development machine If the development machine does not have a copy of the repository on it already then git clone can be used. git clone /path/to/menory/stick/nepoNane.git If there is a copy of the repository already on the machine add the memory stick as a remote and fetch/pull the changes. cd /path/to/local/repo/ git remote add origin /path/to/menory/stick/repoNane..git git pull origin From now on use Git as normal but make sure that whenever a git pull, fetch, or push is performed the memory stick is mounted on the machine, Ensure the memory stick is part of your backup routine, Working with multiple machines —Using CD/DVDs In locked down development environments memory sticks may be blocked. Using Git is still possible, but a little be more inconvenient. Git will happily fetch changes from one copy of a local repository to another. One option then is to simply copy the directory containing the local Git repository to another computer via CD or other media and make changes and commits like normal on both machines. When you want to combine changes select one machine to perform the merge and copy the other repository over to this machine. To pull all the changes into the current branch use: git pull /path/to/other/repo Alternatively you can fetch the changes and create a new branch to store them: git fetch /path/to/other/repo git checkout -b new_branch FETCH HEAD hitpssiww gidbarc melusing-gt-offine! 216, 419072019 Using Git Oftine - James Gibbard's Workshop At this point create a new copy of the repository complete with merges and move it over to the other machine/s. Pull the latest changes into the other repositories or if desired simply replace the whole repository with the new copy. Obviously this is far from optimal. Copying the whole repository directory will include personal settings and files excluded in the .gitignore file. To mitigate this Git clone could be used to duplicate the repository rather than just copying it, but a much better option is to use git bundle. Git bundle A git bundle allows for part or all of a repository to be compressed into a single file in a format that gitis able to clone and fetch from. The workflow works very similar to before, but instead of copying the whole repository directory a git bundle is created. On the first machine create a bundle using: git bundle create repoName.bundle --al1 The ~ ali option bundles the entire repository including all branches and tags. Specific branches or tags can be selected using -b branchNane or -t tagNane Copy the repoName.bundle file to another computer. To clone the repository simply use: git clone repoNane. bundle Changes and commits can be made on any of the computers then like before one machine must be selected to perform the merge. On the non-merging machine make sure all changes are committed and create a bundle using git bundle create repoNane. bundle --all. For larger repositories itis a g00d idea to only bundle part of the repository to avoid transferring more data than needed. For example to only include the last 5 commits on the master branch use: git bundle create repoName.bundle -5 master Itis important that there are no gaps between the commits in the bundle and the commits on the repository where the merging will occur or the process will fail Copy the bundle to the computer where the merge will occur and use git pull ‘/path/to/repoNane.bundle to pull in the changes. Once the merging/rebasing is done create another bundle using git bundle create repoNane.bundle --all or replace --al1 with the desired subset of repos/commits. Then move the bundle file to the other machine/s and use git pull /path/to/repoNane.bundle to update the changes there too, Creating a local remote repository Bundles solve the problem of synchronising Git repositories without a network, but we are still left with multiple computers all likely to be slightly out of sync with each other. If a new developer joins the team who do they copy the repository from? The best option is to select one development hitpssiww gidbarc melusing-gt-offine! 6 419072019 Using Gt ofting- James Gibbare's Workshop machine that will act as the “server”. A bare Git repository can be created on this development machine in addition to a local clone of the repository where the developer will actually work. cd /path/to/store/main/repo nkdir renoteRepoNane git cd renoteRepoNane. git git init --bare Next navigate to the local git repository or create a new one and add the remoteRepoName.git repository as a remote repository. cd /path/to/local/repo/ git renote add origin /path/to/store/main/repo/renoteRepoNane. git git push origin branchName Changes can then be made in the local repository, or pulled from bundles created on other development machines. Whenever changes are made they can be pushed to the remote using git push origin branchNane. Summary The distributed nature of Git allows it to work well without a central server. While the options presented will never be as convenient as just pushing to github they certainly beat the alternative of: main_vi_final_version_with_bobs_extra_patch_finalfinal_version.c Share this: ‘ig (hetps:/wwwgibbard.mefusing-git-offline/?share=twitter&nb=1) {-offine/?shar Ey (https: gibbard.mefusing. ;cebook&nb=1) G+ (https://wmw.gibbard.me/using-git-offine/2share=google-plus-1&nb=1) (httpsi/iwwwgibbard.me/tagicomputers!) 6 (https:/Amwwgibbard.me/tag/git) (https:/iwww gibbard.me/tag/software/) (https:/www gibbard.me/tag/software-development/) (beeps:swwew gibbard. me/tag/software-engineering/) LEAVE A REPLY Enter your comment here. itpssiwwgidbarc melusing-gt-offine! 48, 41302019 Using Gt Oftine - James Gibbard's Workshop < Building a Robotic Arm—Part 2 https://www.gibbard.meybuilding-a-roboticarm-part-2/) Git Cheatsheet > (https://www gibbard.me/git/) Search. RECENT POSTS Cascaded integrator-comb (CIC) filters (https://www.gibbard.me/cic-filters/) Git Cheatsheet (https://www.gibbard.me/git/) Using Git Offiine (https://wwnw gibbard.me/using-git-offline/) Building a Robotic Arm—Part 2 (https://www.gibbard.me/building-a-robotic-arm-part-2/) Building a Robotic Arm—Part 1 (https://www.gibbard.me/building-a-robotic-arm-part-1/) Strandbeest Model (https://www.gibbard.me/strandbeest-model/) ‘One Day Builds— Enigma Machine Emulator (https://www.gibbard.me/one-day-bullds-enigma- machine-emulator/) ‘One Day Builds—FPGA Pong (https:/Avww. gibbard.me/one-day-builds-fpga-pong/) Beginners Guide to I2¢ (https://www.gibbard.me/beginners-guide-to-i2c/) Cheap LED Torch Repair (https://www.gibbard.me/cheap-led-torch-repair/) TAGS (pttps:/wonw.gibbard.meltag/arduino/) (hetpsi/www.gibbard.me/tag/bluetoath/) (nerpsiswwwgibbard.me/tagicomputers/) Div (httpsv/mmw.gibbard.me/tag/diy/) (hitps://mww gibbard, me/tagyelectronics/) (nutpsiswww gibbard.me/tag/fpgal) (https: glbbard.me/tagytrisbee/) (httpsi/Awwwgibbard.me/tag/games/) (hteps:/iwww gibbard.me/tag/git”) (hetps:/iwww gibbard.me/tag/hardware/) (httpsi/iwww gibbard.me/tag/kindle/) (https:/iwww gibbard.me/tag/micracontrollersi) (hrepsisimww gibbard.me/tagione-day-build/) itpssiwwgidbarc melusing-gt-offine! 96 41302019 Using Gt oftne - James Gibbard's Workshop (hetpsiswew gibbard.me/tag/passwords/) (https:/imw gibbard.me/tag/programming/) (hteps:/www gibbard.me/tag/repalr/) (htepsi/imww gibbard.me/tag/robotics/) (httpsi/mwwgibbard.me/tagisecurity/) (httpsi/www gibbard.me/tag/software/) (nttpsis www gibbard.me/tag/software-development/) (hreps://mwwgibbard.me/tag/software-engineering/) (hitps:/iwww gibbard, me/tag/teardown/) (https: gibbard.me/tag/tech/) (httpsi/www gibbard.me/tag/tutorial) (hteps://werw.gibbard.me/tag/vindl/) (https://www gibbard.me/tagiwind-energy/) CATEGORIES Electronics (https://www.gibbard.me/category/electronics/) 9 Computers (https://www.gibbard.me/category/computers/) 5 Uncategorized (https://www.gibbard.me/category/uncategorized/) 1 (HTTPSi/GITHUB.COM/JGIBEARD) (HTTPS/AWW.YOUTUBE.COM/C/JAMESGIBBARD20) Copyright © 2017 James Gibbard - Theme by Colorlib (http://colorlib.com/ Powered by WordPress (http://wordpress.org/) itpssiwwgidbarc melusing-gt-offine! 68

You might also like