Github is just a place to store git repositories (same as Bitbucket or GitLab), with a nice UI and some social features. So you need to use git to use github because github isn’t a thing without it.
Most of the time you only use four commands (
git push to add files and push them up to github, and
git pull to pull the latest modified files down). If you’re working on your own, you don’t generally use
pull that much, but if you’re working with others, you use it constantly.
git clone clones from a given git repo - you use this when you want to bring a repo from online onto your local machine.
git init and
git remote add origin when you’re setting up a project locally and linking it to the repo on github.
If you want to track existing projects, make a new repo on github. While it isn’t linked to your local project, it will just show a set of instructions on how to link it - it looks like this:
Locally you do
In the folder for your project. This creates the
.git folder that all the changes get tracked in. It’s just a collection of text files that contain the necessary information about the project.
Then you add a remote
git remote add origin https://github.com/YourUsername/your-repo-name.git
Which tells git where the online repo is stored.
Then you normally just do
git add . # adds everything in the project ready to commit
git commit -m 'my first commit' # commit everything, along with with a message
git push origin master # push everything up to github
At that point everything should be set, instead of the GitHub webpage with instructions, you’ll see your project instead.
There’s a GUI client if you don’t want to use the command line: https://desktop.github.com/. Note that if you look on the github UI, there are a few places with a button that says “open in desktop”, for example, under the “clone or download” button dropdown on all github projects - when you click those, it will bring the repo into the GitHub desktop client automatically.
And if you do use the command line (I would strongly advise learning it over GUIs but YMMV), then GitHub have a wrapper around git called hub which makes interaction with GitHub easier - the entire above process can be run entirely from your project root rather than creating a repo first on GitHub:
hub create # creates a repo on github and sets the remote
git add .
git commit -m 'my first commit'
EDIT: when you inevitably type
git commit and hit enter, the screen that comes up in the terminal is a text editor called Vim. It is very old, very stable, and powerful, and is designed to be used entirely via keyboard input. But it is horribly cryptic for anyone who has never used it (as an example, the movement commands -
l - come from a time before arrow keys were common on keyboards). Here’s a cheatsheet of basic commands.
Help, I am stuck in Vim:
- Type the character
i to enter insert mode. This allows you to actually type text into the editor.
- Type your commit message - the first line has a max character length, so keep it short. You can type detailed message underneath with no character limit (hit enter, enter at the end of the first line, you want an empty line between the main message and the extra stuff)
- Once you’re done, hit
escape to exit insert mode.
:wq to save and quit - the colon is saying you want to execute a command,
w is for
q is for
- If you’ve made an error or just want to get out, type
:q!, which will forceVim to quit without saving the commit.
- You have now escaped Vim.