Git
How to Upload Local Repo to GitHub
- Create Local Git Repo:
git init
-
Create an Empty Repo on GitHub
-
Link the Local Repo to the Remote GitHub Repo:
- Make sure you use the SSH link (not HTTPS) for your own repo for better authentication security.
git remote add origin git@github.com:username/reponame.git
- If you used the HTTPS URL, change it using
set-url
:
git remote set-url origin git@github.com:username/reponame.git
-
origin
is the default name that prefixes all upstream branches. All upstream branches are referred to asorigin/branch
when viewed in the local repo. -
You can check the remote URL to confirm the change:
git remote -v
- Push Local
main
Branch to theorigin/main
Branch:
git push origin main
- If your default local branch name is
master
, you may encounter an error like:
error: src refspec main does not match any
error: failed to push some refs to 'github.com...'
- Normally, the remote branch and the local branch should have the same name. Change the local branch name by:
git branch -m main
- Now,
git push origin main
should work.
- Set Upstream Tracking: To make the branch remember its upstream branch, use the
--set-upstream
or-u
flag once:
git push --set-upstream origin main
or equivalently:
git push -u origin main
- Next time, you can simply push the branch by using:
git push
Contribute by Forking
-
Fork the Repo on GitHub: Click the “Fork” button on the top right of the repository page to create a copy under your account.
-
Clone the Forked Repo to Local:
git clone git@github.com:username/reponame.git
- Add the Original Repository as Upstream: This time use the HTTPS URL.
git remote add upstream <ORIGINAL_REPO_URL>
- Fetch the Latest Changes from Upstream:
git fetch upstream
- Merge Changes into Your Local Branch: If you want to merge changes from the upstream branch (usually
main
) into your localmain
branch:
git checkout main
git merge upstream/main
- Push to Your Forked Repo: After merging, push the updated local branch to your forked repo on GitHub:
git push origin main
- Create a Pull Request: If you want to propose changes back to the original repo, go to the original repo on GitHub and create a pull request from your forked repo. This allows the maintainers of the original repo to review and merge your changes.
submodule
make a repo as a node inside another repo, treating the whole folder as one file. need to make seperate commits.
CI/CD Pipeline (Github Action)
Continuous Integration, Continuous Delivery