To push a local repository to a remote GitHub repository, follow these steps:
1. Create a Remote Repository on GitHub:
- Go to GitHub and log in to your account.
- Click the + icon in the upper-right corner and select New repository.
- Name your repository and add a description (optional).
- Choose whether the repository should be public or private.
- You can choose to initialize the repository with a README, .gitignore, or license, or leave them empty.
- Click Create repository.
2. Set Up Your Local Repository:
If you already have a local Git repository, navigate to it using the terminal. If you don't, you can initialize a new one:
git init
3. Add the Remote Repository:
Link your local repository to the GitHub repository by adding the remote URL:
git remote add origin https://github.com/your-username/your-repository-name.git
Replace your-username
with your GitHub username and your-repository-name
with the name of your GitHub repository.
4. Add Files to the Staging Area:
If you have new or modified files that you want to push, add them to the staging area:
git add .
This adds all changes in the current directory.
5. Commit the Changes:
Commit the changes with a descriptive message:
git commit -m "Your commit message"
6. Add remote repository :
Push the changes to the remote repository on GitHub:
git remote add origin
Replace remote-repo-url
with the name of the repository you want to push.
you will be asked for user name and password of your git account. For password you should use your personal secret key. you can get from github. (how to get Git token)
7. Push to GitHub:
Push the changes to the remote repository on GitHub:
git push -u origin master
Replace master
with the name of the branch you want to push if it's different (e.g., main
).
to check the name of your local branch you can use
git branch
8. Future Commits and Pushes:
For future commits and pushes, you can simply use:
git push
This should successfully push your local repository to GitHub.