Skip to content

Instantly share code, notes, and snippets.

@CorruptComputer
Last active December 8, 2020 03:07
Show Gist options
  • Save CorruptComputer/3646a3c38e78d4da2b9315cc346c6c65 to your computer and use it in GitHub Desktop.
Save CorruptComputer/3646a3c38e78d4da2b9315cc346c6c65 to your computer and use it in GitHub Desktop.
How to setup and use Git/GitHub on Windows

This guide uses TortoiseGit. While there are other programs out there, this one is very beginner friendly. This guide is for Windows only.

Some videos that are recommended watching for any Git user:

Step 1 - Install Git

  • Go here: https://gitforwindows.org/
  • Download Git.
  • It should look something like Git-2.29.2.2-64-bit.exe
  • Install it and leave everything on default (just keep clicking next).
  • Wait till the installer has finished.

Step 2 - Register on Github

  • Head over here: https://github.com/
  • Click Sign up in the top right-hand corner.
  • Create an account with your username and email.

Step 3 - TortoiseGit

  • Go here: https://tortoisegit.org/download/
  • Download the right TortoiseGit for your system
  • The file should look something like TortoiseGit-2.11.0.0-64bit.msi
  • When the install is done run the first start wizard
  • Make sure your install of Git is being detected
  • Fill out the same username and email address you used on GitHub
  • You can leave everything else as default for now

Step 4 - Forking Code

Forking code allows you to edit it without affecting the main repository, in mose cases you would not have access to edit unless you do so.

  • Head over to the Git repo you want to edit.
    • For example: https://github.com/CorruptComputer/ProtonDB-Tags
  • Click the Fork button in the top right corner.
  • The page you'll be directed to is now your fork. You'll be pushing updates here, and making pull requests to have them merged the main (master) repository.
  • Copy the URL to your fork.
    • Using the same example as above, it would look like this: https://github.com/[YourUsername]/ProtonDB-Tags

Step 5 - Downloading the Code

  • Find where you want the folder for the code to be.
  • Right click and choose Git Clone...
  • The URL field should be filled with the URL of your Fork. If not, paste it in.
  • Click Next and watch flying tortoises bring you your code.

Step 6 - Add the upstream Repo

  • Right click on the folder that was created, and go to TortoiseGit and then click on Settings.
  • Click on Remote under Git.
  • There should be one thing on the list of remotes, with the name: origin.
  • You're now adding the main repository as a source you can pull updates from.
  • In the Remote box type in upstream.
  • In the URL: box put the GitHub URL of the Repo you forked from
  • Click Add New/Save.
  • Click Ok.
  • Almost done!

Step 7 - Updating your Repo

  • Updating your repo with the upstream/master should be done before trying anything.
  • Right-click the folder your repo is in and select TortoiseGit then Pull.
  • Click the radial button next to Remote and make sure upstream is selected next to it.
  • The remote branch should be set to master.
  • Then click Ok. This will pull the latest changes from the master repo.

Step 8 - Making a Branch

Branching your repo is very important for organizing your commits, you should have a different branch for each unrelated code change (e.g. if you wanted to fix a typo in the UI, and you want to add another feature), as Pull requests work off branches rather than commits this will allow you to make a separate Pull Request per change. Doing this streamlines the whole process and will save everyone a bunch of headaches.

  • Right-click in your working folder. Then choose TortoiseGit, and Create Branch...
  • Type in your new branch name
  • (Optional) Tick Switch to new branch
  • Press Okay and your new branch is created

To switch between Branches:

  • Right-click in your working folder. Then choose TortoiseGit, and Switch/Checkout...
  • Choose your Branch then press Okay

Step 9 - Making a Commit

  • A commit is confirmed change of the files in your repo, it's how you make changes permanently to the files in your repo, so try not to commit without making sure it works (though subsequent commits can fix it).
  • As said before, you should use different branches to separate your commits/changes. Don't commit to master. It should be clean, so you can fall back on it if needed.
  • When you're finished editing the code, right click the folder you're working with and choose Git Commit -> "[Your Branch Name]" (Example: Git Commit -> "My_First_Branch")
  • You can then select only the files you want to be committed by ticking or un-ticking them. You should also write a detailed commit summary, detailing what happened in that commit.
  • Click Ok and the commit will be committed to your local repo!

Step 10 - Pushing your code

  • Right-click in your working folder. Then choose TortoiseGit, and Push...
  • Set Local and Remote to the name of the branch you committed before. (e.g. My_First_Branch)
  • Under Destination, set Remote: to origin.
  • Click Ok. This'll upload your changes to your remote repo (the one on GitHub).

Step 11 - Creating a Pull Request

  • Head back to your GitHub repo.
  • Click New Pull Request.
  • Fill out a summary and then create the pull request.
  • You're done! In many cases there may be issues pointed out by other contributors, unfortunate merge conflicts, and other things that will require you to revisit your pull request before it is merged.
  • Optionally, view step 12 for a guide on cleaner commit logs, cleaner commits help when reviewing your code!

Step 12 - Clean commits (Optional)

  • If your commit logs are filthy, full of one or two line commits that fix an error called Whoops or oops, this looks bad and makes it more difficult to look back through the logs. This will help you!
  • Navigate to your local version of the branch
  • Ensure it is up to date with the remote
  • Go to Show log
  • Select all the commits associated with this change or PR
  • Right click and choose Combine to one commit
  • This will open up the standard commit interface for TortoiseGit, with the commit logs of the selected commits merged together
  • Perform the normal routine for a commit
  • Go to push your branch to the remote branch
  • Ensure Force Overwrite Existing Branch (may discard changes) is selected to make sure the PR/Remote updates to contain just this squashed commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment