How to Commit and Push to Github from VSCode (2024 Update)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so I have this sample web project here let's see how we can commit this code and how we can push this to GitHub okay first of all we need to create a repository where we can push this so go to GitHub and create a new repository to create a new repository click on new here and just give this repository the project name so since my project is web project I just calls web- project okay and you can write description here if you want you can also make this a private repository and it will not be accessible to anyone else but I'll just keep it as default for now and just click on create repository now our repository is created and this is the URL for the repository so you can just copy this or just click here to copy it and from next time what you can do is this is also the URL of the repository but you need to add Dot git in the end if you need to push to this URL or if you need to add this as a git origin where you can push it so once we have copied this go back to the project and here click on Terminal and click on new terminal once the terminal is open we need to initialize a git repository locally so that we can push it we cannot directly upload the folder there but what we need to do is create a git repository locally that can be pushed to remote git repository that is GitHub so type G IIT there is git in it and hit enter this will initialize a git repository here so as you can see once this is complete this has changed color and it has become green that means that we have initialized G here and after initializing git we need to add which files to add to git or which files will be tracked by git so there can be multiple files there can be a lot of files in a project so what we'll do is we'll just type git add Dot full stop so this means full stop or period this means that add all the files that will be tracked by G so if you have 100 files all those changes to those files will be tracked by git hit enter and now you just commit get commit D am and then write a message and we'll call it that uh initial commit hit enter again and now we have committed and as you can see this has changed to a normal color p because every change has been committed now what is Commit This commit means that whatever work we have done till now should be pushed to our GitHub so I'll just show you what it means in a minute now let's see how we can push it now the command to push it is get push origin master or this is the branch name we can uh write whatever Branch you have here now if you enter this command you'll get an error at the moment so the error is origin does not appear to be a g repository could not readit from remote repository now this is the command but we have not yet defined what is origin now origin is the remote URL right so we have not yet defined the original origin to be this URL so what we'll do is we'll Define that by typing this command get remote add origin and then that URL once we' have done this now we know what is our origin this is the origin so now we can push to origin and push to master branch of origin hit enter and this time as you can see it is pushed successfully now if I go back to my GitHub and reload this as you can see the index of HTML file is here if I click on this the code is now reflected here so our code has been pushed to GitHub now what is commit so let's let me give you an example so if I write let's say sample page change one here right let's save this and if I push it again I'll get the message everything is up to date now it is because we have changed the file but we have not committed it it means that this will not be a push to GitHub so if I commit this and write change one hit enter okay and now I do comma change two what I'm unsure about change two so I not commit it I'll just push commit still change one so what I'll do is I'll just push again right now what will happen is only the changes that has been committed will be pushed that means we have committed after change one but we did not commit after change two right so only change one will be pushed let's verify this and reload this and as you can see change one is here but change two is not here because we didn't not commit after change to this is how you can commit and push to GitHub if you have any questions let me know in the comments below
Info
Channel: The Code City
Views: 2,222
Rating: undefined out of 5
Keywords: commit and push to github, commit and push to github from vscode, push to github from visual studio code, how to use git in vscode, vscode push to github, push project to github from vscode
Id: 4dkNn93DIx4
Channel Id: undefined
Length: 5min 6sec (306 seconds)
Published: Tue Apr 09 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.