Programación Para Tontos

Git

Tutorial: push your first project to GitHub

Create a GitHub repository and push your local project with git remote and git push.

So far Git has only saved your history on your own computer. Today you'll back it up to the cloud (GitHub) so you don't lose it if your laptop decides to die at the worst possible moment.

Step 1: create an account and a repository on GitHub

Go to github.com, create an account if you don't have one, and click "New repository". Give it a name (for example, my-project) and do NOT check the option to add a README (you already have one locally).

Step 2: connect your local repository to GitHub

git remote add origin https://github.com/your-username/my-project.git

origin is just a nickname (the most common one) for your repository's remote address. You could call it something else, but nobody does, so neither should you.

Step 3: push your commits

git branch -M main
git push -u origin main

-u (for "upstream") tells Git "remember this connection", so next time you just need to type git push on its own. The first time, GitHub will probably ask you to sign in.

Step 4: verify it worked

Reload your repository's page on GitHub. If you see your files there, congratulations: your code no longer depends solely on your computer surviving.

Step 5: the everyday workflow

git add .
git commit -m "Describe what you changed"
git push

This is the cycle you'll repeat constantly: save changes locally (add + commit) and then push them (push). As simple as it sounds, as important as it seems.

What did you just learn?

  • How to create a remote repository on GitHub.
  • How to connect your local project with git remote add.
  • The everyday workflow of add, commit, and push.