Written by Annie Williams
Git is a version control system for writing code. It allows us to all edit the same piece of code, kind of like Google Documents. Git also allows us to revert our code back to previous versions when we break things, test out different versions, and easily decide whose changes we want to keep or discard.
Git is the actual version control system that lives on your computer, while Github is an online service that stores projects. Github is also a good place to find open source projects to contribute to, and network with other people. If you want to contribute code to the JC project, you will need to create an account and install Git - instructions for getting Git based on your machine are here.
Forking is copying somebody else’s repo so that you can completely mess up your own version without any consequences. It also allows the owner of the parent repository to decide which changes get added to the final copy.
Once you fork the Juanjo-Capital repository, it will create a new copy under yourusername/repositoryname. This is the new repository you will add your code to instead of the parent one.
In order to download this new repository onto your computer, you will need to clone by going to the repo page on github.com, clicking the green “clone or download” button, and copying the link. On your command line, use the command git clone
followed by the URL you just copied. If you ever mess things up beyond belief and just want to start over, you can always delete your version and clone the most up to date version from Github.
If you look at the Juanjo-Capital repository, you will see that there is a “master branch.” This is the version of the code that should (in theory) always be a functioning copy of the code that we can fall back on. Code shouldn’t go onto the master branch until we are certain that the code does exactly what we want it to do.
For each new feature you want to code, you should create a new branch and work on it there. This is a helpful way to have multiple versions of the code on your machine at the same time. You can have a fully functioning master branch, as well as other branches with potential versions to play with and screw up.
To create a new branch:
git branch
- this will show you all of your available branches. Make sure you are on the master branch & that your master branch is up to date by fetching (see below)git checkout -b newbranchname
- this will create a new branch (-b
) and put you on that branch (git checkout
).In your terminal/shell, change directories (cd
) into the folder that your new code is in that you want to add to the repository so that everybody else can access it.
git status
- this will show you which files you have changed, and which are ready to gogit add filename
- select the new updated files you want to go up into the repogit commit -m "description of changes"
- after adding the files you want, this command saves a version of your changes on your computer. You can revert back to a commit if you break stuff and want to go back. Don’t forget the quotes around your commit message, or git will get upset.git push origin branchname
- when we push it sends our commit history of the branch we are on to the repository online for everybody else to see. We use origin
to specify that we are sending code to the place we cloned from earlier. Check online to see if your code is there or if you aren’t sure your push worked.Once you’ve committed your changes to your fork, you will need to create a pull request if you want your changes merged into the main repo:
git status
, it might specify that you are already up to date. This is because it is comparing the status of your local version with the version of yourname/reponame, not Juanjo-Capital/reponame.git remote add upstream https://github.com/Juanjo-Capital/jjcap.git
git pull upstream master
to grab the code from the parent repository and merge it into our own work.