Adding and Pushing Branches to GitHub
๐ Mastering Git: Adding and Pushing Branches to GitHub
Hey LinkedIn fam! ๐ Ever wondered how to seamlessly add and push branches to your GitHub repository? ๐ Here's a quick guide to help you navigate through the process:
1. Create a Repository on GitHub:
- Head over to GitHub, create a new repository, and note the repository URL.
2. Initialize Git (if not done already):
- In your local project directory, run:
git init
3. Link Local Repository to GitHub:
- Add GitHub repository as remote origin:
git remote add origin <repository_url>
4. Create and Switch to Branches:
Create new branches using:
git branch <branch_name>
Switch to the branch:
git checkout <branch_name>
5. Add and Commit Changes:
Make changes, add, and commit them to the branch:
git add . git commit -m "Commit message"
6. Push Branches to GitHub:
- To push all branches to GitHub:
git push --all origin
7. Undo Push to Wrong Repository:
Made a mistake? Force push to the correct repository:
git push --force --all <correct_repository_url>
8. Update Remote (if needed):
To update the remote URL:
git remote remove origin git remote add origin <correct_repository_url>
Remember, collaboration is key, and exercise caution with force push when collaborating with others. Happy coding! ๐โจ
#GitHub #VersionControl #CodingTips #Git