PWI Software Documentation Help

Learning Git and GitHub

1. Create your first repository

In this step you will learn how to create a new repository on your PC and add files to it.

Video Guide: GitHub Desktop 1 - Create your first repository

  1. Use GitHub Desktop to create a new repository by selecting File > New Repository

  2. Open and view your repository in Windows Explorer

  3. Open and view your repository in your code editor

  4. Add a file and make some changes

    2. View and commit changes

    In this step you will learn how to view and commit changes to your code.

    Video Guide: GitHub Desktop 2 - View and commit changes

    1. Make some changes to one of your files

    2. Review the changes in GitHub desktop

    3. Add a commit to "save" the changes to your repository

    4. Use the "Discard Changes" command to "undo" changes

      3. Undo and squash commits

      In this step you will learn how to undo changes and "squash" commits.

      Video Guide: GitHub Desktop 3 - Undo and squash commits

      To undo changes:

      1. Make and commit some changes

      2. In GitHub Desktop, select the "History" tab in the commits pane

      3. Choose a commit to undo, right click, and select either "undo commit" or "revert changes in commit"

        Undo Commit

        Deletes the commit but not the changes. The changed files are now staged for a new commit.

        Revert Changes in Commit

        Creates a brand-new commit that reverses the changes that were made. No files are staged for commit.

      To "squash" commits:

      1. Find two commits you want to "squash"

      2. Drag one of them on top of the other

      3. Choose a new commit message for the combined commits

        4. Publish to GitHub

        In this step you will learn how to publish your repository to GitHub, and what it means to fetch, push, and pull the origin.

        Video Guide: GitHub Desktop 4 - Publish to GitHub

        To publish to GitHub:

        1. In GitHub Desktop, click the "Publish repository" button

        2. Choose a repository name and location

        To synchronize changes with GitHub:

        • Click the "Fetch origin" button to check for changes

        • Click the "Push origin" button to copy updates from your PC to GitHub

        • Click the "Pull origin" button to copy updates from GitHub to your PC

            5. Resolve conflicts

            In this step you will learn how manage and merge

            Video Guide: GitHub Desktop 5 - Resolve conflicts

            When pushing new commits, you will be prompted to fix file conflicts (if there are any)

            1. For files that cannot be modified with a text editor (example: *.exe files), choose which version you would like to keep.

            2. For files that can be modified with a text editor (example: code files)

              1. Open the file in any text editor (I recommend VS Code, see above)

              2. Find the sections that are surrounded by carats (<<<<<<< ... >>>>>>)

              3. Decide which code you want to keep, or rewrite the code to combine the differences

              4. Delete the carats that surround your fixed code

              5. Make sure the file is saved

              6. Continue with the merge

              7. Push origin as needed

              6. Create a branch

              In this step you will learn how to create branches.

              Video Guide: GitHub Desktop 6 - Create a branch

              To create a branch:

              1. In GitHub Desktop, select BranchNew Branch in the toolbar

                • Or you can click the "Current Branch" button and select "New Branch"

              2. Name your branch

              To switch between branches:

              In GitHub Desktop, select the "Current Branch" drop-down and choose the branch you want to view

                  7. Merge your branch into main

                  In this step you will learn how to make pull requests and merge a branch into main.

                  Video Guide: GitHub Desktop 7 - Merge your branch into main

                  1. Select the "Preview Pull Request" option from the menu, and

                  2. Resolve any merge conflicts (see lesson 5 above)

                  3. Create a pull request

                  4. Merge the pull request. Make sure that your comments and title are descriptive.

                  5. Delete your branch (both on local and on cloud) if you are done with it

                    8. Clone an existing repository

                    In this step you will learn how to use the clone and fork commands.

                    Video Guide: GitHub Desktop 8 - Clone an existing repository

                    To clone a repository

                    1. In GitHub Desktop, choose FileClone repository

                    2. if you already have access to this repository, you may be able to choose it from the list

                    3. You can also paste a web link using the "URL" tab of the clone window

                    To fork a repository:

                    1. Find the repository you want to make a copy of (on GitHub.com)

                    2. Select the Fork button in the upper right hand corner of the screen

                    3. Follow the steps above to clone the new repository to your PC

                      9. Go back to an older commit

                      In this step you will learn how to go back in history to view your code as it was in a previous commit. This is useful especially when debugging to find out at what point a bug was introduced into your code.

                      Video Guide: GitHub Desktop 9 - Go back to an older commit

                      1. In the History panel of GitHub Desktop, find the commit you want to view

                      2. Right-Click, and select "Create branch from commit"

                      3. Name the branch appropriately

                        10. Cherry-pick a commit

                        In this step you will learn how to use cherry-pick to copy a commit from one branch to another.

                        Video Guide: GitHub Desktop 10 - Cherry pick a commit

                        1. Make sure you are in the branch that contains the commit you want to cherry-pick

                        2. Right-click on a commit and select "Cherry pick"

                        3. Choose the branch you want to pick it into

                        4. Resolve any conflict

                          04 January 2024