How to push to github
A cheat-sheet for pushing to GitHub if you forget
posted by Sink
Here's a step-by-step guide to push your code to the master
branch on GitHub, starting from initializing a new Git repository to pushing the code:
1. Initialize a Git Repository
If you haven't initialized a Git repository in your project directory yet, use:
git init
This command initializes a new Git repository in your current directory.
2. Add Files to the Repository
Now, you'll add your files to the staging area. This is where Git tracks changes to be committed.
git add .
This command adds all your files to the staging area.
3. Commit the Changes
After adding your files, you'll commit them with a message explaining what this commit does:
git commit -m "Initial commit"
4. Create a New Repository on GitHub
- Go to GitHub.
- Click the "+" icon in the top right corner and select "New repository."
- Give your repository a name, and click "Create repository."
Once created, GitHub will give you a URL like https://github.com/yourusername/repository-name.git
.
5. Link Your Local Repository to GitHub
Now, you need to connect your local repository to the newly created GitHub repository. Do this by adding a remote origin:
git remote add origin https://github.com/yourusername/repository-name.git
6. Push Your Code to GitHub
Push your committed code to the master
branch:
git push -u origin master
7. Future Updates
Once you've made more changes in your local repository, the process to push them to GitHub is as follows:
-
Stage the changes:
git add .
-
Commit the changes:
git commit -m "Your message describing the update"
-
Push the changes to GitHub:
git push
Now your code is live on GitHub in the master
branch!