Push to GitHub
Guide for managing your code with Git and sharing your code with GitHub.
When developing an app, here’s a common approach:
- You’re working with some new code to get it to work
- You don’t want to break your existing code, so you copy your current code to another folder (Folder A) and continue working in Folder B
- If you make a mistake, you just delete Folder B and resume with Folder A
This approach is the idea behind version control. Version control is a process that lets you keep checkpoints of your code so that you can refer back to them if needed.
Git is a widely-used version control system used to manage code. Code managed with Git is called a Git repository.
GitHub is popular hosting service for Git repositories. With GitHub, you can share your code and collaborate with others.
In your project, initialize a Git repository:$ git init
Check the status of which files and folders are new or have been edited:$ git status
Tell Git to start tracking your files and folders:$ git add .
If you want to track a single folder or file, use its name:$ git add app/ $ git add config/routes.rb
Verify that everything was committed correctly:$ git status
Save the changes you made, with a message describing what changed:$ git commit -m "Initial commit"
On GitHub, create a new repository with a short, memorable name:
After creating a repository, copy the git commands under the “…or push an existing repository from the command line”, and paste them into the terminal. These commands will add a remote repository, and then push your local repository to the remote repository.