• Post category:Git
  • Post comments:0 Comments
  • Reading time:2 mins read

Jeff Brown

Cloud and DevOps Engineer specializing in Microsoft 365, Azure, and PowerShell. Twitter | LinkedIn

I created a Python script locally on my laptop to solve a coding challenge. However, after completing the script, I decided I wanted to create a repository in my GitHub account to have it available publicly (along with another small script I had completed while working on projects in Codecademy). I went out to GitHub, created the repository with a readme.md file, then realized I wasn’t quite sure how to sync up the two. Some Internet searches and a couple of failed commands later, here is the process I found to complete the task.

First, I realized that I’m not going to get anywhere if I don’t initialize a repo on my local system. I ran the following commands to create a repo in my parent folder, add all the subfolders and files, and make my first commit in the local repo.

git init
git status
git add .
git status
git commit -m "Initial commit"
git status

…do I run “git status” too much?

Next, I added my already created remote repository from GitHub as “origin”:

I tried to pull the origin into my local master branch but got the error fatal: refusing to merge unrelated histories:

Quick search into your favorite Internet search engine should yield that a parameter is available named allow-unrelated-histories that allows unrelated Git repos to be combined together:

At this point, I had successfully pulled down the contents from my remote GitHub repo (just a README.md file) onto my local system. Now everything is staged and I performed a git push to send my local master branch to my remote repo named origin.​​

Success! Now navigating to my new GitHub repo (https://github.com/JeffBrownTech/Python) shows my local files are now uploaded.

If there is a better way to perform this functionality, let me know in the comments or find me on social media.

Leave a Reply