Quick Github setup
This article is all about using Github's core functions without going too much into all of the details. The commands you will see here are the one you're going to use 80-90% of the time.
Github is a really, really, REALLY, REALLY useful tool used for control versioning. It is mostly used for computer code, but it can be used for everything you want. It allows for: - tracking changes into your codes (-> commits made) - collaborative developement (-> Pull requests tab) - Conflict handling (for example, if two persons modified the same file, when uploading, you can merge the different parts together to avoid erasing code) - Bug tracking (-> Issues tab)
And much more. Indeed, not everyone will use every functionnality, and tutorials usually cover everything it can offers to you. But what if you only want a quick startup? For example, for most of my project, I only want to upload my code so I can access it everywhere, and track changes I made.
What will you need for this tutorial
- A Git client (you can grab one here)
- Optionnal: a better terminal than Window's default one, like CMDer
Let's go!
The beginning
Uploading your code to Github (which is called pushing) requires three main steps: add, commit, push. If you want to create a new repository, an initial init step is required too.
Let say that you have an existing codebase on your computer, and you want to upload it on Github. Your codebase looks like this:
Python/
└── my_project/
├── main.py
├── tools.py
└── misc.py
Creating the repository on Github
First, we have to create a repository on Github. This repository will contains the files you want to upload. You can do so by: going on the Github frontpage, then clicking " New " on the left panel. You will be asked to: - Choose a name for the project - Write an optionnal small description - Decide to make it public or private
Once you're done, click " Create ". Tada, your repository is now live! You'll be redirected to another page with a lot of commands. Don't panic! Since your repository is empty, Github is giving you ways to fill it.
Creating the local repository and pushing (uploading) the local code to the remote repository
In our example, we have a pre-existing codebase that we want to upload. He have to initialise a Git repository locally. Using the git prompt:
- Navigate to your code base top folder location using the
cdcommand (e.g.cd C:\Users\YourName\Documents\Programming\Python) OR open a Git console directly in the desired folder (right click -> Git Bash here). - write
git init. This will create a hidden.gitfolder, containing all of the required files. - OPTIONAL: if you want to select which files must (and must not) be uploaded, you have to use a
.gitignorefile. For more information about this, go to the Tips section below. - write
git add *. This will add all the files and folders of the current folder (*is the wildcard operator, which means all) to the next commit. - write
git commit -m "YOUR MESSAGE HERE". This will create the commit. - write
git remote add origin https://github.com/YourName/YourRepo.git. Here, we're telling our local repository where to upload the code (in our case,https://github.com/YourName/YourRepo.git). Note thatoriginis an alias for the url, allowing us to only writeoriginevery time we want to push the code (instead of the whole URL). - finally, write
git push -u origin master. This will push the commit to origin on themasterbranch. For more informations about branches, go to the Tips section below.
If you refresh your repository webpage, the code should be there. Congratulations!
Pushing the code to the created repository
The next time you want to push your code to your remote repository, only the steps 1, 4, 5 and 7 will be required:
cd C:\Users\Kontin\Documents\Programming\PythonORright click -> Git Bash heregit add *git commit -m "YOUR MESSAGE HERE"git push origin masterORgit push
Note that in the 7th step, you can use git push, as the -u origin master tells Git that the default location for pushing your code is at origin master.
TL;DR
First time:
cd C:\Users\YourName\Documents\Programming\PythonORright click -> Git Bash here.git init- OPTIONAL:
.gitignorefile. git add *git commit -m "YOUR MESSAGE HERE"git remote add origin https://github.com/YourName/YourRepo.gitgit push -u origin master
After:
cd C:\Users\YourName\Documents\Programming\PythonORright click -> Git Bash heregit add *git commit -m "YOUR MESSAGE HERE"git push origin masterORgit push