What is Git?
When working on a project, it’s not very optimal to keep passing along a whole project directory for changes. Also, having only one, central master copy can slow down progress. This is especially true when many people are editing different files.
What Git does is instead of having each person modify the master copy in turn, each person submits a series of diff
s. A diff basically just said “I changed this file on these lines.” That way if multiple people work on the same project, it keeps conflicts to a minimum and they can all work at the same time!
Installing Git
If you have a Linux environment in some form (e.g. MinGW, Cygwin), then you almost certainly already have Git. Assuming you don’t though, there are multiple Windows installations for Git. Here is one.
Basic Concepts
In Git, we have branch
es. Each branch is basically a copy of the project, with a log of history of changes. We can create a new branch to work off a copy of the current state of the project, then merge it back in later, after some other people have made their changes.
Setting up
GitHub has a button that says Clone or Download
. Go to a directory and in whatever you used to install git, just say
git clone <url>
and provide you GitHub credentials.
Making a Branch
By default you are on the master
branch. You do not want to be doing work on this branch. The way I have the repository set up, you will actually want to branch off the develop
branch. Issue the following commands:
git checkout develop
git branch <name of your branch>
git checkout <name of your branch>
What this says in order is:
- switch to working off the “develop” version of the project
- make a branch based on that state
- switch to the branch you just made
Committing Your Changes
After you make changes to files, you need to send it back to the repository (so we can use them or do other things with them).
git commit -am "<summary of your changes>"
This creates a diff (technically, it creates a commit, which is a collection of diffs), and saves it locally. If you’re adding a new file, or removing an existing file, you need to:
git add <path to file>
git rm <path to file>
It is not sufficient to just create or delete the file.
All your changes are committed locally, but you need to send the diffs to the server. Use:
git push
To send the diffs to the repository.
Note the first time you push, you need to set the “upstream branch”. This just means that you have these changes on your computer, and Git needs to know what they correspond to in others’ computers. It should be sufficient to just say:
git push -u origin <name of your branch>
Changing Branches
It’s common to be working on multiple different features at a time. You generally don’t want to do them in the same branch. Swap between them (after committing you changes) with git checkout
.
git checkout <second branch>
swaps to the second branch, and
git checkout <first branch>
switches back.
Creating a Pull Request
When a branch passes tests and looks goo to go to make its way into the master copy, it’s time to create a pull request. Go to Github and click the Pull Requests
button. Then click “New Pull Request”. For base, select develop
, and for compare, select the branch you think is ready. Then create the pull request, and let me know that you did.
If you understand and think you can do all of the above, then you’re able to be a team member. I encourage you to learn a bit more nuanced control (such as using git status
/ git add
instead of just git commit -am
), but these are just the bare basics.
There are also good GUI tools to do Git. I’m not familiar with any of them myself, but if you find one that works, and you can branch/commit/push with it, then you also meet the qualifications to be a team member.