Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to Add Code on GitHub Repository?
Next article icon

How to Add Code on GitHub Repository?

Last Updated : 10 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

GitHub is a powerful platform for hosting and sharing code. Whether you’re working on a solo project or collaborating with others, adding code to a GitHub repository is essential. Here’s a step-by-step guide on how to add your code to a GitHub repository.

Steps to Add Code on GitHub Repository

Step 1: Create a New Repository on GitHub

  1. Log in to GitHub: Open your web browser and log in to your GitHub account.
  2. Create a new repository:
    • Click on the "+" icon in the top-right corner and select "New repository."
    • Enter a repository name.
    • Add a description (optional).
    • Choose the repository type (public or private).
    • Click "Create repository."

Step 2: Initialize Git in Your Project Directory

  1. Open your terminal: Open your command line interface (CLI) or terminal on your computer.
  2. Navigate to your project directory:Use the cd command to navigate to the directory containing your project. For example:
    cd path/to/your/project
  3. Initialize a Git repository:
    • Run the following command to initialize a new Git repository in your project directory:
      git init

Step 3: Add Your Code to the Repository

  1. Add files to the staging area: Use the git add command to add your files to the staging area. To add all files, run:
    git add .
  2. Commit your changes: Use the git commit command to commit your changes. Add a meaningful commit message:
    git commit -m "Initial commit"

Step 4: Connect Your Local Repository to GitHub

  1. Add the remote repository:
    • Copy the URL of your GitHub repository. It should look like https://github.com/yourusername/your-repository.git.
    • In your terminal, add the remote repository using the following command:
      git remote add origin https://github.com/yourusername/your-repository.git
  2. Verify the remote repository:
    • Ensure the remote repository is added correctly by running:
      git remote -v

Step 5: Push Your Code to GitHub

  1. Push your changes:
    • Use the git push command to push your changes to the GitHub repository:
      git push -u origin main
    • If your default branch is master, use master instead of main.

Step 6: Verify Your Code on GitHub

  1. Check your repository:
    • Go to your GitHub repository in your web browser.
    • Refresh the page to see your files and commit history.

Tips for Effective Use

  • Frequent Commits: Make small, frequent commits to track changes more effectively and keep your commit history clean.
  • Branching: Use branches to work on new features or bug fixes without affecting the main codebase.
  • Pull Requests: When your feature or fix is ready, create a pull request to merge your changes into the main branch.

Next Article
How to Add Code on GitHub Repository?

A

anuragsingh1022
Improve
Article Tags :
  • Web Technologies
  • Git
  • GitHub

Similar Reads

    How to Fork a GitHub Repository?
    GitHub is a great application that helps you manage your Git repositories. Forking a GitHub repository is a common practice that allows you to create your own copy of a repository hosted on GitHub. In this article, we will learn more about Git-Fork and its uses. Table of Content What is GitHub Repos
    3 min read
    How to Git Clone a Remote Repository?
    Git is a powerful version control system that allows developers to track changes, collaborate on code, and manage projects efficiently. One of the fundamental operations in Git is cloning a remote repository. This article will guide you through the process of cloning a remote Git repository. Prerequ
    3 min read
    How to Open a GitHub Repository in VS Code Online?
    It often feels as if one could view the files or code from a GitHub repository online in a code editor to search the files, code components, or simple text(and indeed, it does enhance the readability and management of the code) without having to clone it to your device. What if I tell you it hardly
    2 min read
    How to Create a Tag in a GitHub Repository?
    Tags are one of the important parts of Git and GitHub. We can see in the case of open source projects that the release of a particular version is attached with a tag. Tags are used to memorize a specific moment in history. Even after making multiple changes to the code, we can get back to the partic
    3 min read
    How To Clone a Repository From Gitlab?
    Cloning a repository in Git involves creating a local copy of a project from a remote server. This allows you to work on the project on your local machine and later push your changes back to the remote repository. GitLab, one of the popular platforms for hosting Git repositories, provides a straight
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences