Congratulations! You’ve just completed your coding project, and now it’s time to share your hard work with the world. Git is a powerful version control system that helps you manage and track changes to your source code, making collaboration and deployment easier. In this step-by-step guide, we’ll walk you through the process of deploying your source code to Git repository for the first time.

Why we have to “Deploying Your Source Code to Git repository” ?

If you completed all steps as follow, you’ve successfully deployed your source code to Git for the first time. Now, your project is safely stored in a version-controlled environment, and you can collaborate with others, track changes, and deploy updates more efficiently.

Step 1: Install Git

Before you can deploy your source code to Git, you need to make sure Git is installed on your local machine. If you don’t have Git installed, download and install it from the official website (https://git-scm.com/). Once installed, open your terminal or command prompt to verify the installation by running

git --version.

Step 2: Create a Git Repository

  1. Navigate to the root directory of your project using the terminal.
  2. Run the following command to initialize a new Git repository:
git init

This command creates a hidden folder named “.git” in your project directory, which will store all the version control information.

Step 3: Add Your Source Code to the Repository

Use the following command to add all your project files to the staging area: The . indicates that you want to add all files in the current directory to the staging area.

git add .

To check the status of your files and ensure they’re added to the staging area, run:

git status

Step 4: Commit Your Changes

Now it’s time to commit your changes to the Git repository with a meaningful message that describes the changes you made. Use this command:

git commit -m "Initial commit"

Replace “Initial commit” with a description of your changes.

Step 5: Create a Remote Repository

  1. Visit a Git hosting platform such as GitHub (https://github.com) or GitLab (https://gitlab.com).
  2. Sign in or create an account if you don’t have one.
git repository
Image by Freepik

Step 6: Connect Your Local Repository to the Remote Repository

  1. On the Git hosting platform, create a new repository.
  2. Follow the platform-specific instructions to connect your local repository to the remote one. Typically, this involves adding a remote repository URL, which you can get from your hosting platform.

Step 7: Push Your Code to the Remote Repository

Push your code to the remote repository using the following command:

git push origin master

This command pushes your code to the “master” branch of your remote repository. Replace “master” with the branch name you’re working on if it’s different.

Conclusion & Key Takeaways

  1. Git is a powerful version control system that helps you manage and track changes to your source code.
  2. To get started, install Git, create a Git repository, add your source code, commit your changes, and connect to a remote repository.
  3. Pushing your code to a remote repository makes it accessible for collaboration and deployment.
  4. Using Git allows you to maintain a history of changes and work more efficiently in a team or as an individual developer.

Cover Image : Image by Freepik