|
| 1 | +#Setting Up *With* a Fork with Visual Studio 2015 |
| 2 | + |
| 3 | +See also [Setting up a Repo in VS 2015](SettingUpRepoInVS2015.md). |
| 4 | + |
| 5 | + As mentioned, the first option is great if you only want read-only access or you have read-write access to the GitHub repo. |
| 6 | + If you want to be able to submit pull requests, you need to create a fork (which you will have read-write access to) |
| 7 | + and use that for your updates. To do this do the following: |
| 8 | + |
| 9 | + 1. Open a web browser to the GitHub project page (in our case https://github.com/Microsoft/perfview) |
| 10 | + 2. Make sure you have a GitHub account and that you are logged in (If you are logged into GitHub your user name |
| 11 | + in the very upper right corner of display will be an icon for your user identity). See https://github.com |
| 12 | + for information on getting an account. The instructions will tell you to download GIT tools. You can |
| 13 | + do this if you like, however Visual Studio 2015 has all the GIT functionality you will need so you don't |
| 14 | + have to have them (but it does not hurt, and they are useful for more advanced scenarios). |
| 15 | + 3. Click on the 'Fork' button in the upper right corner. If it asks you were to put he fork, you will wish |
| 16 | + to put it in your account area (same as your user name). Note that if the fork already exists it simply |
| 17 | + navigates to the existing fork, so this is also a way of finding a fork if needed. |
| 18 | + 4. Once that has completed (it does not take long), it will take you to a page that looks VERY similar to |
| 19 | + the original but is in fact a clone. It should have a URL like https://github.com/vancem/perfview that has |
| 20 | + your user name in it. |
| 21 | + 5. At this point you can follow the instructions above for setting up a local clone (Option 1). The only difference is |
| 22 | + that the GitHub URL will be the *URL of the fork and not the main repository*. You may also wish to give |
| 23 | + it a local name that makes it clear that it is a fork (for example the local directory name for my fork is perfview-vancem). |
| 24 | + Otherwise keeping track of which were direct clones (option 1) and which were not (option2) becomes more difficult. |
| 25 | + |
| 26 | +### Creating a 'upstream' Repository alias. |
| 27 | + |
| 28 | +At this point you should have a local clone of your personal read-write fork of the main repository. However this |
| 29 | +is a FULLY INDEPENDENT clone which will NEVER SEE ANY UPDATES from the main repository unless you explicitly integrate |
| 30 | +(merge) them. To make easy to do this updating, it is good to create an alias for the original master repository. Here |
| 31 | +we show you how to do that in Visual Studio 2015. |
| 32 | + |
| 33 | + 1. Click on the View -> Team Explorer menu item |
| 34 | + 2. Click on the top bolded header (may say 'Home' or 'Changes', ...) and right click on 'Settings' |
| 35 | + 3. Click on the 'Repository Setting' hyperlink |
| 36 | + 4. One of the sub-item in Repository setting page is 'Remotes' and under that is a 'Add' hyperlink. Click on that. |
| 37 | + 5. This will bring up a dialog box where you are prompted for a Name and a 'Fetch' and 'Push' location. it |
| 38 | + There is also a checkbox (which should be checked) that says the Fetch and Push are the same. |
| 39 | + 6. Fill in the name as 'upstream' and fill the 'Fetch' textbox with the URL OF THE MAIN RESPOSITORY (in our |
| 40 | + example this is https://github.com/Microsoft/perfview. It should automatically fill in the 'Push' dialog. |
| 41 | + 7. Click the 'save' button. This new name should now show up in the 'remotes' list. |
| 42 | + |
| 43 | +What this does is name the original main repository 'upstream'. This makes it easier to refer to it in later commands |
| 44 | +(like updating your fork with updates from the main repository). You will see that your GitHub repo already has |
| 45 | +a short name called 'origin' (this is very standard name to use for your 'cloud' repo that your local repo works with). |
| 46 | +'upstream' is a traditional GIT name for the repository that a fork was created from. |
| 47 | + |
| 48 | +### Pulling updates from the Main (upstream) Repository into your Fork |
| 49 | + |
| 50 | +Sooner or later, the main repo will have updates that you will want to pull into your fork. This |
| 51 | +section tells you how to do this. |
| 52 | + |
| 53 | +If you go to your fork's GitHub web page (e.g. one that has your user name in it like https://github.com/vancem/perfview) |
| 54 | +you will see that there is a line just before the description of files in the repo like |
| 55 | + |
| 56 | + * This branch is even with Microsoft:master. |
| 57 | + |
| 58 | +Or it may say |
| 59 | + |
| 60 | + * This branch is 4 commits behind Microsoft:master. |
| 61 | + |
| 62 | +You can see that this item is an indication of 'in sync' the master branch of your personal fork is with the master branch |
| 63 | +of the main repo (which we have named upstream). From time to time you will want to pull in |
| 64 | +all these changes to bring your fork up to date. We do this in three steps |
| 65 | + |
| 66 | + 1. Fetching all changes from the upstream repository. This step make all the changes (commits) |
| 67 | + in the fetched repository AVAILABLE for merging, but does not actually do any merging of branches. |
| 68 | + 2. Merge the changes from the upstream/master branch into the LOCAL repository's master branch. |
| 69 | + 3. Push the changes from the LOCAL repository's master branch into the master branch of the GitHub fork (called origin). |
| 70 | + |
| 71 | +####Step 1: Fetching All Commits for the Upstream Repository. |
| 72 | + |
| 73 | + 1. Click on the View -> Team Explorer menu item |
| 74 | + 2. Click on the bolded header (may say 'Home' or 'Changes', ...) and right click on 'Sync' option. This will bring |
| 75 | + up the synchronization page, and one of the options will be 'Fetch' click on that. This brings up a dialog filled |
| 76 | + out with 'origin' which says it will pull all changes from the 'origin' repository (which is your GitHub fork). |
| 77 | + However we don't want that since we are interested in the changes from the original master (which we named upstream) |
| 78 | + You should be able type a down arrow and 'upstream' should be one of the choices (since we added 'upstream' as a |
| 79 | + known remote). Select 'upstream' and click the 'Fetch' button. That will fetch all the changes from 'upstream', |
| 80 | + and put them in the LOCAL GitHub repository. So far we have made or local repository bigger (more commits) but we have |
| 81 | + not changed any existing branch (the transitive closure of any branch is the same as it was before). |
| 82 | + |
| 83 | +####Step 2: Merging the LOCAL repository's master branch to include changes from upstream/master |
| 84 | + |
| 85 | + 1. Click on the View -> Team Explorer menu item |
| 86 | + 2. Click on the top bolded header (may say 'Home' or 'Changes', ...) and right click on 'Branches' item which show you |
| 87 | + all branches associated with the LOCAL repository (that is the repository clone on your local disk). There will |
| 88 | + be at least one branch called 'master' as well as branches under 'remotes/origin' (these are branches in the |
| 89 | + private fork on GitHub) and 'remotes/upstream' (these are branches in the original main repository). |
| 90 | + 3. Make sure that the 'active branch' (the one in bold) is 'master'. If not double click on master to make it |
| 91 | + the active branch. If it fails (and it could easily fail because you have modified files), you will have to |
| 92 | + commit or undo those changes before proceeding. Ultimately you want 'master' to be the active branch. |
| 93 | + 4. Click on the 'remotes/upstream/master' branch, right click on it and select 'merge from' This says we want |
| 94 | + to integrate (merge) all changes from the upstream/master branch into the currently active branch (which is master). |
| 95 | + A dialog will come up with text boxes filled out. Simply click the 'Merge' button. |
| 96 | + |
| 97 | +In most cases this merge operation goes without a hitch and Visual Studio will auto-commit the merge. However if there |
| 98 | +is a merge conflict with changes that you have made to 'master' (you really should never do that, put changes in some other |
| 99 | +branch (see below)), then you will need to resolve them and commit the merge explicitly. |
| 100 | + |
| 101 | +####Step 3: Pushing the LOCAL repository to your GitHub Fork |
| 102 | + |
| 103 | + 1. Click on the View -> Team Explorer menu item |
| 104 | + 2. Click on the bolded header (may say 'Home' or 'Changes', ...) and right click on 'Sync' option. This will bring |
| 105 | + up the synchronization page, and one of the options will be 'Sync' click on that. This will push all your |
| 106 | + changes to 'origin' (which is your GitHub fork) as well as pull down any changes from origin (there should be |
| 107 | + none as you are the only one modifying this fork). |
| 108 | + |
| 109 | +At this point you should be able to go to your GitHub web page for the fork and see a line like this |
| 110 | + |
| 111 | + This branch is even with Microsoft:master. |
| 112 | + |
| 113 | +Which says that you have integrated all the changes from the original main repository into your private fork. |
| 114 | +Congratulations, you have successfully brought your private fork up to date with respect to its upstream master. |
| 115 | + |
| 116 | + |
| 117 | + |
0 commit comments