Master Git: Essential Commands to Push Your Code Like a Pro
Table of contents
You've come to the right place. In this blog, I will provide a comprehensive, step-by-step guide on how to set up your GitHub profile from scratch. We will start by creating a new GitHub account, setting up your profile with a professional picture and bio, and configuring essential settings to enhance your experience.
Once your profile is ready, I will walk you through the process of creating a new repository and explain the importance of initializing it with a README file. We will then move on to installing and configuring Git on your local machine, ensuring that you can seamlessly interact with your GitHub repositories.
Finally, I will guide you through the process of How to push code to GitHub from Visual Studio. This will include setting up Visual Studio to work with GitHub, committing your changes, and synchronizing your local repository with the remote one on GitHub. By the end of this guide, you will have a fully set up GitHub profile and the knowledge to manage your code repositories efficiently.
How to Push Code to GitHub
Follow the steps below to push your code to GitHub from Visual Studio Code and watch your projects come to life online.
Step 1. First, open your GitHub profile.
Step 2. Click on the "New" button on the left side of the GitHub page.
Step 3. A new page will open where you need to enter your Repository Name.
Step 4. You can also add some optional descriptions.
Step 5. Decide if you want your repository to be private or public. If you don't want anyone to see your project, choose private. Otherwise, select the public.
Step 6. Scroll down the page and click on the create repository
button.
Step 7. You will be redirected to the next page.
Step 8. Launch Visual Studio Code and open your project code in it.
Step 9. Click on the terminal option and start a new terminal.
Step 10. Type git init
in the terminal to initialize your files, and hit enter.
Step 11. Type git add .
to add all your files, and hit enter.
Step 12. Type git commit -m "commit message"
to commit your changes, and hit enter.
Step 13. Type git branch -M main
to switch to the main branch.
Step 14. Go back to the GitHub page and copy the repository link.
Step 15. Return to the terminal and type git remote add origin "repo-link"
and press enter.
Step 16. Type git push origin main
to push all your files to the repository. Wait a few seconds, and your code will be live in your repository.
Github Command List to Push Code
git init
git add .
git commit -m "commit message"
git branch -M main
git remote add origin "repo-link"
git push origin main
Conclusion
By following this guide, you now have the skills to set up a GitHub profile, create repositories, and push your code using Visual Studio Code. With these essential Git commands and processes at your fingertips, managing your code and collaborating with others will be more efficient and streamlined.
Keep practicing, and soon pushing code to GitHub will become second nature. Happy coding!
Subscribe to my newsletter
Read articles from Aditya Kumar Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Aditya Kumar Gupta
Aditya Kumar Gupta
Hi there! I'm Aditya, a passionate Full-Stack Developer driven by a love for turning concepts into captivating digital experiences. With a blend of creativity and technical expertise, I specialize in crafting user-friendly websites and applications that leave a lasting impression. Let's connect and bring your digital vision to life!