To push code to GitHub, follow these essential steps:
-
Create a new repository on GitHub.
-
Initialize a Git repository locally in your project folder with
git init
. -
Add your project files to the repository:
git add .
-
Commit your changes with a message:
git commit -m "Your commit message"
-
Link your local repo to GitHub by adding a remote origin:
git remote add origin https://github.com/USERNAME/REPOSITORY_NAME.git
-
Push your code to GitHub's main branch with:
git push -u origin main
For later pushes, simply use git push
.
Note that some older local repositories may use "master" instead of "main" as the branch name. This sequence will upload your local project files and commit history to your GitHub repository, making the code available remotely.