Creating a git repository onto github.
To put your project up on GitHub, you will need to create a repository for it to live in.
GitHub repositories can house a wide range of projects, including open source projects. You can share code in open source projects to create better, more dependable software. Repositories can be used to collaborate with others and track your progress. .
- Login to "Github"
- In the upper-right corner of any page, select + then click New repository.
- Type a short, memorable name for your repository. For example, "hello-world".
- Optionally, add a description of your repository. For example, "My first repository on GitHub."
- Choose a repository visibility. For more information, see "About repositories."
- Select Initialize this repository with a README.
- Leave other fields as it is.
- Click Create repository.




Initializing a Git repository
If your locally-hosted code isn't tracked by any VCS, the first step is to initialize a Git repository.
- Open Git Bash.
- Navigate to the root directory of your project.
- Initialize the local directory as a Git repository. By default, the initial branch is called main.
- If you're using Git 2.28.0 or a later version, you can set the name of the default branch using -b.
- Add the files in your new local repository. This stages them for the first commit.
- Commit the files that you've staged in your local repository.
git init
git init -b main
git add .
OR:
git add -A
git commit -m "Initial commit"
Here in the above code we gave a shortcut "-m" so that we can write the commit message quickly, if you want to add commit message seperately remove -m and it will open vim editor.
Connect Local Repository with GitHub Remote Repository.
As we all know, the GitHub repository is a cloud-based repository. This means that whatever data is available in the Local Repository can be posted to the GitHub Remote Repository. We previously created a GitHub remote repository called "hello-world", now it's time to send our local data to a GitHub remote site.
- Navigate to your repository on github.
- Follow this steps after first commit.
- Update the default branch name from "master" to "main"
- Copy remote repository URL field from your GitHub repository, in the right sidebar, copy the remote repository URL.
- In Terminal, add the URL for the remote repository where your local repostory will be pushed.
- Sets the new remote:.
- Push the changes in your local repository to GitHub.

git branch -M main

git remote add origin <remote repository URL>
git remote -v
git push -u origin main
Here in the above code we gave a shortcut "-u" so that we can track the relationship between local branch and the remote branch. This means that, in the future, when you run git push or git pull without specifying the branch names, Git knows which remote branch to push to or pull from. It sets the default remote branch for your local branch.
Conclusion:
In Conclusion, adding your local repository to GitHub enhances collaboration, provides a secure and accessible backup, facilitates project management, and integrates with a variety of tools to streamline development workflows. Whether you're working on personal projects, collaborating with a small team, or contributing to open source, GitHub serves as a powerful platform for version control and project management.