How to Push Code to a GitHub Repository

  Рет қаралды 38,087

Cameron McKenzie

Cameron McKenzie

9 ай бұрын

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!

Пікірлер: 78
@cameronmcnz
@cameronmcnz 9 ай бұрын
There a full tutorial on how to push an existing project to a new GitHub repo over on TheServerSide: www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-push-an-existing-project-to-GitHub
@Frankie_Freedom
@Frankie_Freedom 9 ай бұрын
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
@cameronmcnz
@cameronmcnz 9 ай бұрын
Yup! That's exactly how it works!
@DJ_Melech
@DJ_Melech 7 ай бұрын
Thanks for this. The "proper" way you did first time solved my issue.
@cameronmcnz
@cameronmcnz 4 ай бұрын
Happy to have helped! Thanks for watching and commenting.
@dominicabah5431
@dominicabah5431 5 ай бұрын
Thank you so much! I got drifted here for something else and this helped clear that as well.
@cameronmcnz
@cameronmcnz 5 ай бұрын
Happy that you drifted in this direction! And super glad I could help!
@ivanphone4917
@ivanphone4917 9 ай бұрын
I like the easy approach to adding a project to GitHub. Much easier to push existing code to GitHub that way.
@cameronmcnz
@cameronmcnz 9 ай бұрын
Trying to make adding new projects to GitHub as easy as I can!
@kabwere
@kabwere 3 ай бұрын
This has helped me with my first repo. Thank you!
@cameronmcnz
@cameronmcnz 3 ай бұрын
Glad I could help! Git and GitHub gets a lot easier once you get the initial connectivity all worked out!
@RandallNewman
@RandallNewman 6 ай бұрын
Thank you! The -f approach is what I needed actually!!
@cameronmcnz
@cameronmcnz 6 ай бұрын
Sounds rather unchristian when you put it that way, but I'm glad it helped! Just know that forcing a commit onto a repo shared with others might mess up their repos, so others might have to do a fresh clone the next time they fetch from the server. Of course, if this is just the first setup operation, it shouldn't matter. People won't be pulling from the repo until the project is set up in git.
@RandallNewman
@RandallNewman 6 ай бұрын
This was the first commit on a repo I created on bitbucket and had the .gitgnore checked. When I did that I was like -fooey! Then I found your video and all is well. Thanks again.
@asimdhali6447
@asimdhali6447 9 ай бұрын
At last I find the effective video, thanks this tutorial helps me lot
@cameronmcnz
@cameronmcnz 9 ай бұрын
Glad I could help!
@reamageorge9648
@reamageorge9648 Ай бұрын
Thank you so much, got what I needed in the first 5 mins.
@nickl3135
@nickl3135 3 ай бұрын
You the man, thanks for the clear instructions ! I swear Github can be quite the pain at times.
@cameronmcnz
@cameronmcnz 3 ай бұрын
Glad I could help! I actually uploaded a newer video to show some alternatives to the force push. Some clone shenanigans and some git rebase options. Plus, I'm improved my mic and camera. I put together a 2 hour Git and GitHub video as well. Honestly, once you start to understand the philosophy behind Git and GitHub, it all falls into place and becomes a lot easier! www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-push-an-existing-project-to-GitHub
@nickl3135
@nickl3135 3 ай бұрын
@@cameronmcnz Great, I will definitely be checking those videos out, need to gain some further understanding !
@bautipiaggio
@bautipiaggio 7 ай бұрын
Very useful my man, thank you very much
@cameronmcnz
@cameronmcnz 7 ай бұрын
Things get a lot easier with Git and GitHub once you get stuff like this out of the way, I promise!
@SrihariVemana-on6nk
@SrihariVemana-on6nk 8 ай бұрын
Thank you so much, this was very helpful!
@cameronmcnz
@cameronmcnz 4 ай бұрын
Did you use the cheat method or the proper method?
@lastvoyager7847
@lastvoyager7847 3 ай бұрын
Thanks man. You helped a lot!
@cameronmcnz
@cameronmcnz 3 ай бұрын
Glad I could help. Git and GitHub gets a lot easier when these connectivity issues are out of the way. Happy Git!
@kirklimbu
@kirklimbu 3 ай бұрын
Thanks for simplifying. It helped.
@cameronmcnz
@cameronmcnz 3 ай бұрын
I was worried I overcomplicated it! Once you get Git and GitHub integrated, the whole Git experience becomes a whole lot easier. Thanks for watching and subscribing.
@ascertain3987
@ascertain3987 3 ай бұрын
Very helpful tutorial.
@cameronmcnz
@cameronmcnz 3 ай бұрын
Thanks for the kind words! Once you get your local Git project pushed to GitHub, things get a lot easier.
@smartoluwamuyiwabeyioku8766
@smartoluwamuyiwabeyioku8766 16 күн бұрын
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
@peacemunii910
@peacemunii910 Ай бұрын
This was great thank you!
@cameronmcnz
@cameronmcnz Ай бұрын
Happy to be of service!
@arhampersonal
@arhampersonal 8 ай бұрын
Thank you soo much sir 🙂❤️
@cameronmcnz
@cameronmcnz 4 ай бұрын
Glad I could help!
@mintiankai
@mintiankai 7 ай бұрын
Thanks. It is helpful.😀
@cameronmcnz
@cameronmcnz 4 ай бұрын
Glad I could help!
@_sorridente_
@_sorridente_ 9 ай бұрын
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?
@cameronmcnz
@cameronmcnz 9 ай бұрын
The latest Git install still defaults to master, and I try to keep my tutorials as standard as possible, so that is often a reason. I'm surprised I didn't point it out in this video, but in almost all videos I do I mention the switch to main and that such a naming strategy is now preferred. It actually causes a lot of problems when a Jenkins server defaults to looking for master (which the latest version still does), while the latest GitHub repo only has main. It's a topic I've written about a lot over on TheServerSide. Here's an article from 2019: www.theserverside.com/opinion/Master-slave-terminology-alternatives-you-can-use-right-now Also one specifically about Git and GitHub: www.theserverside.com/feature/Why-GitHub-renamed-its-master-branch-to-main Sadly, the transition has been slow.
@cameronmcnz
@cameronmcnz 9 ай бұрын
Oh, and send my appreciation to your friend. And to you for subscribing!
@gabehorno
@gabehorno 8 ай бұрын
I swear to god Git is the most confusing shit ever to use. It was easier to learn C++ than to use Github
@cameronmcnz
@cameronmcnz 4 ай бұрын
I put together this Git and GitHub tutorial just for you. I'm going to make you love Git! kzbin.info/www/bejne/omPco32qrNR2lacsi=e8RJQt1T71B0u_zB
@berndblubb5243
@berndblubb5243 Ай бұрын
@@cameronmcnz I am afraid I have to ack @gabhorno's comment. All programs using subcommands seem to be overly complicated and obscured. I assume most programmer's just want to do a bit of version manament, without having to travel a long learning curve and get frustrated by confusing terms like origin, master, HEAD, and other badly explained terms. From my point of view for most smaller development teams systems like svn or even cvs are much better suited for their purposes than git.
@fuhayho
@fuhayho 2 ай бұрын
thanks for helping me LOL
@cameronmcnz
@cameronmcnz Ай бұрын
You helped yourself by finding the resource you needed. That's what being a dev is all about - knowing how to find the answers. The only person to thank is yourself!
@user-qp8zy2wp6g
@user-qp8zy2wp6g 8 ай бұрын
excellent
@cameronmcnz
@cameronmcnz 4 ай бұрын
Glad I could be of assistance!
@arhampersonal
@arhampersonal 7 ай бұрын
thanks a lot ( :
@cameronmcnz
@cameronmcnz 4 ай бұрын
You're most welcome!
@sunnykwan5630
@sunnykwan5630 9 ай бұрын
How do you make version control on the approach of copying folder. I guess what you modify in the original folder will not affect the copied folder. So, whenever u change something in your project, that will actually not recorded.
@cameronmcnz
@cameronmcnz 9 ай бұрын
Yeah, you'd just start doing development in the folder where you copied everything. Or, you can just copy the hidden .git folder that gets created in the new folder back into the original one. That's where Git keeps all ofits files.
@sunnykwan5630
@sunnykwan5630 9 ай бұрын
@@cameronmcnz ok thank you so much. Already done it.
@cameronmcnz
@cameronmcnz 9 ай бұрын
How did it work? @@sunnykwan5630
@sunnykwan5630
@sunnykwan5630 9 ай бұрын
@@cameronmcnz I just use your way by copying the folder
@cameronmcnz
@cameronmcnz 9 ай бұрын
I hope I didn't overcomplicate things. My hope was to make it a bit easier than editing remote references in a config file. Have fun with Git! @@sunnykwan5630
@Stylemoongirl
@Stylemoongirl 7 ай бұрын
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???
@cameronmcnz
@cameronmcnz 7 ай бұрын
It's a hidden file, so to see the .git folder you'd need to change your folder settings to show hidden files. Windows? I think from Git BASH you can do an ls -a command and it shows hidden folders too! Also, just run the git status command in that folder. If the command works, you're good!
@Stylemoongirl
@Stylemoongirl 7 ай бұрын
@@cameronmcnz this really works Thaaaaaaaaaaaaaaaaaaaank youuuuuuuuuu I spent 2 weeks to solve this problem with github! this really works THANKSSSSSSSSSSSS
@HaifengZhu-pn3uq
@HaifengZhu-pn3uq 5 ай бұрын
When I right click on my computer, it doesn't have "Open Git Bash"
@cameronmcnz
@cameronmcnz 5 ай бұрын
If you're using Windows, you need to install Git. But I've got you covered with this video on installing Git here: kzbin.info/www/bejne/b3SkqKmBnrF8edUsi=fszI9fIvBrDmT-Od
@donaldleclerc8021
@donaldleclerc8021 9 ай бұрын
What about a git pull --rebase then git push instead of rewriting the remote history with - f ?
@cameronmcnz
@cameronmcnz 9 ай бұрын
Actually, I was going to add that as a third option but everyone always gets intimidated by a rebase. I might add that to the actual article I wrote on theserverside. It's a smart suggestion. www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-push-an-existing-project-to-GitHub
@cameronmcnz
@cameronmcnz 4 ай бұрын
On your suggestion I added the rebase option to this video here on git remote add origin. kzbin.info/www/bejne/oKKUg4J4nNJ4sNk
@sen7826
@sen7826 8 ай бұрын
But if we do it the easy way, we seem to have to lose any git history in our local folder. I would like to do it the easy way but I don't want to lose the history either
@cameronmcnz
@cameronmcnz 8 ай бұрын
For this video, I'm never sure if people have a new, fresh project without git, or an existing git repo with its own history merging into another one with a history. I kinda assumed the local project had no git. You just want to get it to GitHub. In your situation, a rebase may be better than a forced merge!
@sen7826
@sen7826 8 ай бұрын
@@cameronmcnz thank you
@user-tm5gx9iu6q
@user-tm5gx9iu6q 9 ай бұрын
How can I edit existing files?
@cameronmcnz
@cameronmcnz 9 ай бұрын
The ones on GitHub or the ones locally on your file system? GitHub has an online editor for files you have pushed from your existing project to GitHub so long as you have appropriate permissions. Otherwise, just edit those files on the filesystem.
@mindhealth4393
@mindhealth4393 7 ай бұрын
The push* is not working for me. does anyone knows why. i am using mac. i got zsh: no matches found: push*
@cameronmcnz
@cameronmcnz 7 ай бұрын
Are you on the main or master branch? Make sure the same branch exists both on the server and client. Git still defaults to master. GitHub to main. You might need to create a master branch on GitHub.
@daydreamers8254
@daydreamers8254 4 ай бұрын
my VSC terminal is demanding i authenticate my github on a website which is asking for INSANE amounts of money per month...i did everything right in the gitbash terminal for my project the repoository exists but the project will NOT upload unless i shell out money. it's been free and i've been using it for free for YEARS so WTF is going on?!?!
@cameronmcnz
@cameronmcnz 4 ай бұрын
Is it GitHub that is asking for money? That doesn't seem right to me.
@daydreamers8254
@daydreamers8254 4 ай бұрын
@@cameronmcnzplease help me (also why are my comments gone / not showing up) i just typed a long important comment bout how i ot it work finally only for it to all vanish on commenting. now i forgot. and it won't work again, and there's no more money issues popping up. it just simply won't work. i use VSC so i have Bash terminal In the project directory ALREADY. then i do the following: git init git add . git commit -m "message here" git remote add origin (paste in repo URL) git push -u origin master and it doesn't go to the repo. even if i get the error you got, and do the thing you did, still nothing happens. the ONLY thing that DOES happen is a git folder is made, a repo is made, and a readme.md is made. but the project never makes it. i wish to the good lawd i wrote it down or put it in a notepad... anything to remember the easiest part of coding. i can tell you build orders from all 4 races in wc3 roc that came out in 2001 or 02, same witht its expansion, in all match ups even map based, naming hotkeys, naming hero ability hotkeys, it's SAD i can remember something from 20 years ago so well but i can't remember something from 15 hours ago that worked... even with videos and github showing you "how to do it" - it still does NOT work.... idk what to do bro, unless you can get on discord (make a throw away or join my 0 budget one...) i honestly give up for trying to upload to github tonight. unless you reply, PLEASE reply, i D O apologize for my spam comments and SUPEr LONG messages... but i can not help it...
@Eag757
@Eag757 8 ай бұрын
Academia think students have all day to work on a projects, and give instructions that were effective back in 2000's. Professors aren't adapt to fast pace modern world of tomorrow.
@cameronmcnz
@cameronmcnz 4 ай бұрын
I'll try and stay up to date with my Git and GitHub tutorial! kzbin.info/www/bejne/omPco32qrNR2lacsi=e8RJQt1T71B0u_zB
@mehmeteminmese979
@mehmeteminmese979 5 ай бұрын
Is it that easy ??????🤣🤣🤣🤣
@cameronmcnz
@cameronmcnz 5 ай бұрын
When you follow my git tutorials it is!!!
Using Git & GitHub in VSCode: Stage, Commit, and Push
14:51
Max on Tech
Рет қаралды 24 М.
How to add a new project to an existing GitHub repository
5:45
Cameron McKenzie
Рет қаралды 85 М.
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 39 МЛН
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 73 МЛН
Create Your First AWS Lambda Function | AWS Tutorial for Beginners
12:44
Tiny Technical Tutorials
Рет қаралды 125 М.
How to upload a project / folder to GitHub
9:14
Abstract programmer
Рет қаралды 63 М.
I teach you how to code an object in JavaScript... like a DAWG
7:49
Spicy Coding Academy
Рет қаралды 22
How to Undo a Pushed Git Commit - Reset & Revert a Git Commit After Push
12:25
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 988 М.
Everything You'll Need to Know About Git with ThePrimeagen | Preview
14:43
How to Push Code to Github from Visual Studio Code (2023)
9:00
The Code City
Рет қаралды 92 М.
Git vs. GitHub: What's the difference?
10:06
IBM Technology
Рет қаралды 376 М.
Github Actions CI/CD - Everything you need to know to get started
12:21
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 39 МЛН