DEV Community

Cover image for How to push fresh code to GitHub?
HLonare
HLonare

Posted on

3 2

How to push fresh code to GitHub?

Are you a beginner with GitHub and fascinated with its code collaboration features? Do you want to try it and don’t know where to start exactly?

Well, you can always go to GitHub and learn about its CLI or download a UI for your machine and start there.

But what if you already have some awesome code running on your local machine, and you would like it to be pushed to GitHub.
Let's just go to GitHub and create a repository:

Now go to your local folder where your code is located.

If you have recently created a nice project on your local environment, and you want to upload it to GitHub, follow this commands on your terminal, and you will be good to go.
Remember you have to first CD into your project folder

git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/harshalone/strapi-v4.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

If you face issues on GitHub, like history difference for example.
If the problem is “main and master are entirely different commit histories.”, the following will works

git checkout master   
git branch main master -f    
git checkout main  
git push origin main -f
Enter fullscreen mode Exit fullscreen mode

For the ones who have problem to merge into main branch (Which is the new default one in Github) you can use the following:

git checkout master  
git branch main master -f    
git checkout main  
git push origin main -f
Enter fullscreen mode Exit fullscreen mode

The following command will force both branches to have the same history:

git branch [Branch1] [Branch2] -f
Enter fullscreen mode Exit fullscreen mode

You can find step by step tutorial with pictures on How do I push fresh code to GitHub?

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay