Beginner's Guide: Pushing Code to an Empty GitHub Repository Using Git Bash

Beginner's Guide: Pushing Code to an Empty GitHub Repository Using Git Bash

Introduction:

In the world of software development, GitHub has become a central hub for collaborative coding projects. Knowing how to push your code to a GitHub repository is a crucial skill. In this beginner's guide, we will walk you through the process of pulling an empty repository from GitHub, creating three folders (ec2, s3, iam), adding code files to each folder, and pushing your code using Git Bash, all without relying on any graphical user interfaces (UI).

Let's get started!

Step 1: To create a repository in GitHub using the user interface (UI), follow these steps:

  1. Open your web browser and go to the GitHub website: https://github.com.

  2. Sign in to your GitHub account. If you don't have an account, you'll need to create one.

  3. Once you're signed in, you'll be redirected to your GitHub dashboard. Click on the "+" icon in the top right corner and select "New repository" from the dropdown menu.

  1. On the "Create a new repository" page, you'll need to provide the following information:

    • Repository name: Choose a descriptive name for your repository.

  • Description (optional): Add a brief description to provide more details about your project.

  • Public or Private: Choose whether you want your repository to be public (visible to everyone) or private (visible only to you and collaborators you invite).

  • Initialize this repository with a README: Select this option if you want to create an initial README file for your repository.

  • Add .gitignore: If your project requires ignoring certain files, select an appropriate .gitignore template from the dropdown menu.

  • Choose a license (optional): If you want to specify a license for your project, select an appropriate license from the provided list.

    1. Once you've filled in the necessary information, click on the "Create repository" button at the bottom of the page.

Congratulations! You have successfully created a new repository on GitHub using the UI. You can now add files, make commits, and collaborate with others on your project.

Step 2: Clone the Empty Repository

First, we need to clone the empty repository from GitHub to our local machine. Here's how you can do it:

  1. Open Git Bash on your computer/cmd.

  2. Navigate to the directory where you want to clone the repository using the cd command. For example, cd Documents will take you to the Documents folder.

  1. Use the following command to clone the empty repository from GitHub:

  • Open your repository in Github and copy the link.

- Go to your terminal and write the below given command.

git clone github.com/tusharkumar2302/infrasity-git-tu..

Replace <repository-url> with the URL of the empty repository on GitHub. Press Enter to execute the command.

  1. Voila! You now have a local copy of the empty repository in your current directory.

Step 3: Create Folders and Code Files

Now that we have the repository, let's create three folders (ec2, s3iam) and add code files to each folder:

  1. To create the "ec2" folder, execute the following command:

“mkdir ec2”

  1. Repeat the above step for creating the "s3" and "iam" folders:

“mkdir s3, mkdir iam”

  1. Navigate to the "ec2" folder using the cd command:

“cd ec2”

4. Make three files in ec2 folder by giving a command:

“touch main.tf provider.tf variable.tf

5. Repeat steps for the "s3" and "iam" folders to create code files specific to each folder.

6. Copy the code from the below given repository and paste it in the specific files in each folder

https://github.com/tusharkumar2302/infrasity-git-tutorial.git

Step 4: Push the Code to the Repository

Now that we have added our code, let's push it to the repository:

  1. Go back to the main directory of the cloned repository using the cd command:

“cd ..”

  1. Check the status of your repository to ensure that Git recognizes the new files and folders. Use the following command:

“git status”
Git will display the untracked files.

  1. Add all the new files and folders to the staging area using the git add command:

“git add .”

  1. Commit the changes with a meaningful message using the git commit command:

“git commit -m "Added code files for EC2, S3, and IAM"
Replace the commit message with a descriptive one.

  1. Push the committed changes to the remote repository using the git push command:

“git push”

Conclusion:

Congratulations on completing your journey to push code to an empty GitHub repository using Git Bash! By following the steps outlined in this beginner's guide, you have learned how to clone an empty repository, create folders and code files, and push your code changes—all through the command line interface.

Remember, mastering these fundamental Git and GitHub concepts will prove invaluable as you progress in your coding journey. Version control and collaboration are vital aspects of modern software development, and Git provides a powerful framework for managing codebase changes effectively.

As you become more comfortable with these processes, feel free to explore advanced Git features and additional Git commands to further enhance your development workflow. Practice makes perfect, so don't hesitate to experiment and get hands-on experience with Git Bash and GitHub.

Keep in mind that while the steps provided here are simplified for beginners, there is a vast world of Git and GitHub concepts to explore. Dive deeper into topics like branching, merging, resolving conflicts, and collaborating with others to unlock even more capabilities within Git.

Now that you have the knowledge and confidence to push code to an empty GitHub repository using Git Bash, you're ready to embark on your coding adventures. Happy coding, and may your repositories be filled with amazing projects and contributions!

For detailed course on terraform please visit:

https://infrasity.com/p/build-deploy-configure-ci-cd-with-github-actions-workflow

Did you find this article valuable?

Support Infrasity Blog by becoming a sponsor. Any amount is appreciated!