Now that I’ve been using GitHub for more than a year for most of my personal (and some commisioned) projects, I think I feel comfortable enough to explain Git basics and how it makes your life easier.
I wouldn’t expect you to move to Git if I only explained how it works (there are several hundred guides around), so I’m going to give you some of the improvements it made to my development life:
- On September, I moved to New York and I couldn’t bring my desktop PC with me. I needed a PC to work so I got a laptop. Since I had being using GitHub to save all my work, I could easily import all the projects with some commands that we will explore later.
- GitHub also serves as a backup for all your code. If your PC goes in fire, you will still have your code saved in GitHub’s servers (but you will have to expend some money on a new PC 😔).
- Collaboration is key. If you manage public projects, you can let people collaborate with you. You can’t expect people to fix issues and add features for you if your code isn’t public, and that’s one fundamental feature of Git.
- If you’re a student, you can get a free GitHub license by enrolling into their education pack.
Creating your first repo
It doesn’t matter if you have a free or a premium account, you can create as many public repositories as you wish. You can create them by clicking the “Plus” symbol in the top and adding all the details:
Once you are done, you need to copy the link provided and go to your favourite IDE or console and use these commands:
# Creates a git repository in the folder you currently are git init # Sets the online repo to your recently created GitHub repo git remote add origin <Your URL> # Add all the files to git. You may want to add files you don't want to a .gitignore file git add .
Uploading your changes
You can now start working as you would normally! Whenever you think you need to upload all your changes use:
# (OPTIONAL) Add newly created files git add . # Commit your changes to the local repo. NOTE: Use the -S argument if you would like to sign your commits git commit -m 'Your commit message' # Pushes your commits to GitHub (branch master). The -u argument saves your selection and you can later use git push only git push -u origin master
That’s it! You now have your code backed up online available to all the developer community (if your repo is public).
Additional features you get
GitHub isn’t only about files full of code, you also get issue management, where you can file all your nasty bugs and have a thread for each one; Pull requests, a way for others to make changes to your code; and much more! GitHub also offers an API that, for example, I have already integrated with the Lab page, where you can see all the latest commits for all my public projects.
You can see all the cool features you get at https://github.com/features.
I hope you liked the way I currently work and you start using it in your own projects. GitHub is the easiest way to backup your code online although there are other alternatives such as GitLab and BitBucket.
Today, we learnt how to create our first repository and how to push your changes online. Check out the Git Handbook for a more comprehensive guide.