Git and Github are the same thing, right?
No, they are their own separate products. Let’s go over the differences between the two, along with how to set it up and get working on a Windows machine.
Differences between Git and GitHub
Git is version control software. It keeps track of edits, additions, and deletions to files in a directory of your choosing. Git is installed locally on your computer. It might seem a little odd that the software tracks changes on your local machine if you’re the only one using it. But with it, you can look at previous versions of the software and roll back any changes. Did you break something that was working yesterday? You can roll back changes, or even look at the difference between one version of a file to another.
GitHub is an online repository of Git code, plus some additional changes. GitHub makes it easy to collaborate with your team on the same code. GitHub allows you to make “forks” of other people’s code, and make changes of your own. It also has an issue tracker to log bugs in the software.
So, Git is version control software that is installed on your local machine, and GitHub is an online repository of the Git code, along with some other features. There are alternatives to GitHub such as SourceForge and GitLab among others, but this article only covers GitHub.
A little deeper with Git
Git works in 3 different areas:
- The first is the working directory. In the example below, that will be
C:/Users/moffat/Code/sleep tracking. This is the local folder where your files are stored.
- Next is the staging area. This area holds files that are going to be part of the next commit.
- The last area is the
.gitfolder where the snapshot of changes are stored after the commit command is run.
- There is kind of a 4th area, a repository like GitHub. Once the files are pushed to GitHub, this area has an online copy of the files.
First, install Git from https://git-scm.com/downloads. After it downloads, run the installer. The default options are fine, unless you want to customize anything on your own. In my walkthrough below, I will use the option from the second screen of the installer called Git Bash Here. this adds the option from the right click menu to open Git Bash on the selected folder.
Side note: If you have Windows 11 and dislike the simplified right click menu Microsoft pushes on you, you can get the original one back. Follow option 2 linked here. Then either restart explorer.exe or reboot your computer. Now the right click menu will be as it should have been all along. It’s always there under “Show More Options”, but we don’t need to add an unnecessary click.
Find the folder you want to work from, and right click it. In the right click menu, or under Show More Options for Windows 11 users that still see the simplified right click menu, select Git Bash Here. If you still see the simpler menu, do yourself a favor and follow the steps in the previous paragraph.
This opens Git Bash on that folder. In my case, it opens in
C:/Users/moffa/Code/sleep tracking, and it will look like this:
The first command we want to run is
git init. This initializes the Git repository. When it does this, a hidden folder called
.git is added to the folder you’re working with. This is where configuration files are kept, and where the the history of changes is kept.
Stage and commit the files
To commit the files to Git, we first need to “stage” the files. To do this, run
git add -A (
-A adds all files in the
/sleep tracking folder) in the Git Bash window, then run
git commit -m "Initial Commit". Adding
-m gives a message to the commit. The first time will normally be “Initial Commit”, and additional commits will have a note about what changed in the new version of the file.
git add puts the files in the staging area shown above, then
git commit commits the snapshot to the
.git folder. Running the
git status command shows you the status of the tree — is one folder out of sync from another? Is there a file that is added but not committed? It will give you a message here.
Adding files to GitHub
Open up GitHub and create a new repository. Give the repository a name, and make sure it’s public if you’re going to share it with someone. You can check the Add a README file box to add a
README.md file that describes what the project is about. Alternatively, you can create this file in Git Bash with the
touch README.md command. This creates the
README.md file in the master directory
Click Create Repository to make the repository you named above. On the next screen, look towards the bottom where it says …or push an existing repository from the command line. Copy the 3 lines of code in this section, and paste them in the Git Bash window. This uploads the files to your GitHub repository.
Open that repository on GitHub to see the files that were committed, along with the
README.md file if you created one.
Working with Git and GitHub
Make changes to the files on your local machine. If you add files, run
git add <filename> to stage them, then
git commit to commit them to Git. When you want to update the files on GitHub, run the
git push command to push them to the remote directory.
That’s the difference between Git and GitHub. We also went over some basics on how to set up a folder with Git, how to create the repository on GitHub, and how to sync the two together.