Create a file on your local machine using GitBash and push it to a GitHub repository.

Charly AdolfusCharly Adolfus
2 min read

Create a file on your local machine using GitBash and push it to a GitHub repository.

To create a file from your local machine via GitBash and push it to a GitHub repository, follow these steps:

  1. Open GitBash: Launch GitBash on your local machine.

  2. Use the mkdir command to make a folder.

  3. Use the cd command to navigate to the myapp directory.

  4. Use the git init command to initialise git on your local repository

  5. Create a New File: Use the touch command to create a new file. For example, to create a file named index.html

  6. Add Content to the File: Open the file with a text editor (like vi) and add some content.

     vi index.html
    

    After adding content, use the command :wq + enter to save and exit the editor.

  7. Let's connect the local repository to the GitHub repository using the following command: git remote add origin <url>

  8. Stage the File: Use the git add command to stage the new file.

  9. Commit the Changes: Commit the changes with a descriptive message.

  10. Push to GitHub: Push the changes to your GitHub repository.

By following these steps, you will have successfully created a file on your local machine using GitBash and pushed it to your GitHub repository.

The next step is to create a pull request:

The following window pops up:

To resolve the issue of branches having entirely different commit histories, you can use the following commands:

git checkout master
git branch main master -f
git checkout main
git push origin main -f

These commands will forcefully create a new main branch from the master branch and push it to the remote repository.

0
Subscribe to my newsletter

Read articles from Charly Adolfus directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Charly Adolfus
Charly Adolfus

I have a solid background in cloud computing ideas and a strong desire to use cloud technology to address practical issues. I am an enthusiastic and driven cloud developer. Equipped with practical AWS and Azure knowledge, I'm excited to advance in the cloud development industry and add value to dynamic teams. I am chronicling my daily experiences in the realm of cloud computing on this blog.