%3CLINGO-SUB%20id%3D%22lingo-sub-1419990%22%20slang%3D%22en-US%22%3EKeeping%20your%20local%20GitHub%20Repo%20in%20Sync%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1419990%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20many%20times%20have%20you%20forked%20a%20GitHub%20repository(repo)%20and%20worked%20on%20your%20copy%20of%20it%2C%20made%20changes%2C%20pushed%20them%20back%20to%20the%20original%20and%20went%20off%20to%20do%20something%20else.%26nbsp%3B%20Then%20a%20couple%20of%20weeks%20later%20you%20thought%20of%20something%20else%20you%20wanted%20to%20contribute%20but%20your%20copy%20of%20the%20repo%20was%20out%20of%20date%20and%20you%20had%20to%20spend%20time%20getting%20it%20back%20in%20line%20with%20the%20original%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYip%2C%20that%E2%80%99s%20me.%20I%E2%80%99ve%20tried%20all%20sorts%20of%20techniques%20and%20methods%3B%20however%2C%20I%E2%80%99ve%20found%20a%20workflow%20that%20works%20for%20me.%26nbsp%3B%20I%20want%20to%20share%20how%20I%20do%20it%20with%20you%20all%2C%20now%20there%20maybe%20other%20ways%20of%20doing%20this%20and%20I%E2%80%99d%20love%20to%20hear%20them%20but%20this%20is%20the%20way%20I%20do%20it%20at%20the%20moment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EThis%20article%20assumes%20that%20you%20have%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2F%3FWT.mc_id%3Ditopstalk-blog-salean%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20Code%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fgit-scm.com%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGit%3C%2FA%3E%20installed%20on%20your%20local%20computer.%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EFork%20a%20Repository%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20to%20find%20a%20repository%20(repo)%20that%20I%20want%20to%20work%20on%20within%20GitHub.%20%26nbsp%3BThen%20click%20on%20the%20Fork%20button%3C%2FP%3E%0A%3CCENTER%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitsync1.jpg%22%20style%3D%22width%3A%20611px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195670i98C55F72FCE71FAB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22gitsync1.jpg%22%20alt%3D%22Github%20Repository%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGithub%20Repository%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCENTER%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20fork%20has%20completed%20GitHub%20will%20load%20your%20copy%20of%20the%20repository.%26nbsp%3B%20The%20next%20step%20is%20to%20take%20a%20copy%20of%20that%20repo%20onto%20your%20computer%20for%20editing%2C%20to%20do%20that%20we%20carry%20out%20an%20operation%20called%20Clone.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFind%20the%20green%20button%20that%20says%20Clone%20or%20Download%20on%20your%20screen.%3C%2FP%3E%0A%3CCENTER%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitsync2.jpg%22%20style%3D%22width%3A%20550px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195671i8BF718F930C8435F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22gitsync2.jpg%22%20alt%3D%22Github%20Repository%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGithub%20Repository%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCENTER%3E%0A%3CP%3EIf%20you%20click%20on%20that%20button%20a%20URL%20will%20display%2C%20copy%20that.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20open%20Visual%20Studio%20Code%20and%20click%20on%20Terminal%20%26gt%3B%20New%20Terminal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%E2%80%99ll%20see%20a%20console%20open%20at%20the%20bottom%20of%20your%20screen%2C%20in%20here%20we%20want%20to%20change%20to%20the%20directory%20you%20want%20to%20copy%20the%20documentation%20into.%26nbsp%3B%20I%20usually%20use%20the%20Documents%20folder%20on%20my%20computer%20for%20GitHub%20files%2C%20so%20I%20type%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ecd%20documents%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20then%20issue%20the%20command%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Egit%20clone%20**INSERT%20THE%20URL%20YOU%20COPIED%20EARLIER**%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20go%20back%20to%20the%20original%20repo%20and%20copy%20the%20clone%20URL%20from%20there.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWithin%20your%20terminal%20console%2C%20you%20need%20to%20change%20into%20the%20directory%20of%20your%20clone%20repo%2C%20in%20my%20case%20the%20directory%20is%20called%20Test%20so%20within%20my%20Terminal%20I%20type%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3ECd%20.%5CTest%5C%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20I%20type%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGit%20remote%20add%20upstream%20**INSERT%20the%20original%20repo%20clone%20URL**%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CCENTER%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitsync3.jpg%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195672iE386677443797106%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22gitsync3.jpg%22%20alt%3D%22Sync%20Github%20repository%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ESync%20Github%20repository%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCENTER%3E%0A%3CP%3EYou%20can%20now%20push%20and%20pull%20from%20your%20copy%20of%20the%20repo%20and%20also%20pull%20(and%20push%20if%20you%20have%20contributor%20rights)%20to%20the%20original%20repo%2C%20which%20will%20help%20later%20on.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EMake%20your%20contributions%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20that%20you%20have%20the%20repo%20on%20your%20local%20machine%20you%20can%20make%20the%20changes%20that%20you%20want%20to%20make%2C%20commit%20them%20to%20your%20repo%20and%20then%20issue%20a%20pull%20request%20to%20the%20original%20source.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EKeeping%20your%20copy%20in%20sync%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20it%E2%80%99s%20maybe%20been%20a%20few%20days%20or%20weeks%2C%20since%20you%20made%20your%20initial%20fork%2Fclone%20and%20you%20want%20to%20make%20another%20contribution%2C%20but%20there%20have%20been%20changes%20to%20that%20repo%20since%20and%20your%20copy%20is%20out%20of%20date.%26nbsp%3B%20To%20bring%20your%20copy%20in%20sync%2C%20this%20is%20the%20process%20that%20I%20do.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWithin%20my%20terminal%20within%20Visual%20Studio%20Code%20I%20navigate%20to%20the%20location%20of%20my%20repo%20copy%20and%20type%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGit%20checkout%20master%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20makes%20sure%20I%20am%20on%20the%20right%20branch%20of%20the%20repo.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20I%20type%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGit%20pull%20upstream%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CCENTER%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitsync4.jpg%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195673iDD3DA048797EA3B5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22gitsync4.jpg%22%20alt%3D%22Sync%20Github%20repository%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ESync%20Github%20repository%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FCENTER%3E%0A%3CP%3EWhich%20pulls%20changes%20from%20the%20original%20repo%2C%20meaning%20any%20changes%20the%20owner%20of%20that%20repo%20has%20made%20or%20merged%20from%20other%20contributors%20is%20now%20copied%20on%20my%20machine.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can%20now%20make%20the%20changes%20I%20want%20to%2C%20add%20them%20to%20my%20copy%20of%20the%20repo%20and%20then%20do%20a%20pull%20request%20to%20merge%20with%20the%20original.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20means%20I%20am%20not%20working%20on%20old%20files%20and%20encounter%20issues%20when%20I%20try%20to%20merge%20my%20contributions%20with%20the%20original%20repo.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ESummary%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%E2%80%99s%20a%20workflow%20that%20takes%20a%20few%20steps%20and%20a%20few%20times%20to%20remember%20but%20I%E2%80%99ve%20found%20it%20works%20quite%20well%20and%20saves%20me%20any%20issues%20when%20I%20issue%20my%20pull%20requests%20later%20on.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1419990%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gitsync.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F195675iF17C9CB33292C93C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22gitsync.jpg%22%20alt%3D%22Keeping%20your%20local%20Github%20Repo%20in%20Sync%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EKeeping%20your%20local%20Github%20Repo%20in%20Sync%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ELet's%20have%20a%20look%20at%20how%20you%20can%20keep%20the%20local%20copy%20of%20a%20GitHub%20repo%20in%20sync%20with%20the%20master.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1419990%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESarah%20Lean%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

How many times have you forked a GitHub repository(repo) and worked on your copy of it, made changes, pushed them back to the original and went off to do something else.  Then a couple of weeks later you thought of something else you wanted to contribute but your copy of the repo was out of date and you had to spend time getting it back in line with the original?

 

Yip, that’s me. I’ve tried all sorts of techniques and methods; however, I’ve found a workflow that works for me.  I want to share how I do it with you all, now there maybe other ways of doing this and I’d love to hear them but this is the way I do it at the moment.

 

This article assumes that you have Visual Studio Code and Git installed on your local computer.

 

Fork a Repository

The first step is to find a repository (repo) that I want to work on within GitHub.  Then click on the Fork button

Github RepositoryGithub Repository

 

Once the fork has completed GitHub will load your copy of the repository.  The next step is to take a copy of that repo onto your computer for editing, to do that we carry out an operation called Clone.

 

Find the green button that says Clone or Download on your screen.

Github RepositoryGithub Repository

If you click on that button a URL will display, copy that.

 

Now open Visual Studio Code and click on Terminal > New Terminal.

 

You’ll see a console open at the bottom of your screen, in here we want to change to the directory you want to copy the documentation into.  I usually use the Documents folder on my computer for GitHub files, so I type:

 

 

 

cd documents

 

 

 

And then issue the command

 

 

 

git clone **INSERT THE URL YOU COPIED EARLIER**

 

 

 

Now go back to the original repo and copy the clone URL from there.

 

Within your terminal console, you need to change into the directory of your clone repo, in my case the directory is called Test so within my Terminal I type

 

 

 

Cd .\Test\

 

 

 

Now I type

 

 

 

Git remote add upstream **INSERT the original repo clone URL**

 

 

 

 

 

Sync Github repositorySync Github repository

You can now push and pull from your copy of the repo and also pull (and push if you have contributor rights) to the original repo, which will help later on.

 

Make your contributions

 

Now that you have the repo on your local machine you can make the changes that you want to make, commit them to your repo and then issue a pull request to the original source.

 

Keeping your copy in sync

 

So, it’s maybe been a few days or weeks, since you made your initial fork/clone and you want to make another contribution, but there have been changes to that repo since and your copy is out of date.  To bring your copy in sync, this is the process that I do.

 

Within my terminal within Visual Studio Code I navigate to the location of my repo copy and type

 

 

 

Git checkout master

 

 

 

This makes sure I am on the right branch of the repo.

 

Then I type

 

 

 

Git pull upstream

 

 

 

 

 

Sync Github repositorySync Github repository

Which pulls changes from the original repo, meaning any changes the owner of that repo has made or merged from other contributors is now copied on my machine.

 

I can now make the changes I want to, add them to my copy of the repo and then do a pull request to merge with the original.

 

It means I am not working on old files and encounter issues when I try to merge my contributions with the original repo.

 

Summary

 

It’s a workflow that takes a few steps and a few times to remember but I’ve found it works quite well and saves me any issues when I issue my pull requests later on.