How to Push Code to a GitHub Repository

preview_player
Показать описание
I get lots of developers asking me how to push existing code in an existing project to a remote GitHub repository.

There are two ways to push an existing project to a GitHub repo:

- The easy way
- The proper way

The easy way? Simply clone the existing GitHub repo, copy your project code into the clone repository, and then push back to the server. Your existing project will be added to the GitHub repo in the cloud.

This way works if there are existing files in the GitHub repo.

Alternatively, you can do a git init in your existing project, then create a new GitHub repository, and add the GitHub repo as a remote. Then you push.

A lot can go wrong in this approach. Often the branch name of main or master is incorrect and can cause a problem.

Furthermore, if there is code in the repo already, this will fail. You'll need to force the Git push.

Personally, I think the easy way to add existing code to a GitHub repo is the right approach. Others say adding the remote reference is the right way to add a project to an existing GitHub server.

Let me know what you think in the comments!
Рекомендации по теме
Комментарии
Автор

There a full tutorial on how to push an existing project to a new GitHub repo over on TheServerSide:

cameronmcnz
Автор

This actually clears it up, I don't use github much, but what I always had a hard time understanding was switching repos. Now I see that you do the setup on each separate folder that you are attaching to each different repo

Frankie_Freedom
Автор

Thank you so much! I got drifted here for something else and this helped clear that as well.

dominicabah
Автор

Thanks for this. The "proper" way you did first time solved my issue.

DJ_Melech
Автор

I like the easy approach to adding a project to GitHub. Much easier to push existing code to GitHub that way.

ivanphone
Автор

Thank you so much, got what I needed in the first 5 mins.

reamageorge
Автор

This has helped me with my first repo. Thank you!

kabwere
Автор

At last I find the effective video, thanks this tutorial helps me lot

asimdhali
Автор

Thank you so much, this was very helpful!

SrihariVemana-onnk
Автор

Thank you! The -f approach is what I needed actually!!

RandallNewman
Автор

the way he said "i don't care" 😂😂😂😂😂

VICTORGITAU-dooh
Автор

Very useful my man, thank you very much

bautipiaggio
Автор

You the man, thanks for the clear instructions ! I swear Github can be quite the pain at times.

nickl
Автор

Thanks for simplifying. It helped. <3

kirklimbu
Автор

You can use the command "git switch -c branch_name" to create another branch and you can go ahead and run the "git push -u origin branch_name", and it works fine

smartoluwamuyiwabeyioku
Автор

Thank you for the easy way. Any idea how to easily push new or modified codes from our existing cloned repository in our computer to the github repository? Thank you.

TerryGoh-zgru
Автор

A friend shared this video with me; I like your teaching style and have subscribed. Is there a reason you haven't updated your default branch from master to main?

_sorridente_
Автор

Using the git UI is the best and easier option

alexdominguess
Автор

I swear to god Git is the most confusing shit ever to use. It was easier to learn C++ than to use Github

gabehorno
Автор

After paste my url in comman, I didn't get any new folder called .git in my repos folder! there just one file read me! why???

Stylemoongirl