Git Commands Tutorial | Git Clone, Add, Commit, Push, Pull, Checkout, Branch, Status

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to webstylepress if you are new here  consider subscribing and hit that bell icon   previously i shared common git commands and  easy way to use git on windows by using git   gui git bash and git for windows find link for  that tutorial in description or in this video   in this video i will show you how can you  use those git commands with the git bash or   terminal for mac or linux or ubuntu  you have got your terminal for windows   you have got command prompt or powershell but  i will prefer git for windows git for windows   gives you get bash utility  that is similar to terminal get bash we will use git bash to clone a repo  from github we will practice git colon get add get   commit get push get pull get branch get branch  new get checkout and get status and such commands   these are common commands and in most  cases you only need these to do the job   and learn to use these commands and you are good  to go with version control system to use git you   should generate ssh keys for pc and register those  keys with github or get lab to do all of this   this is how github recognizes your pc and allows  files transfer between pc and your github repos from your profile you will register  keys ssh keys here ssh and gpg keys   you will generate those keys in your  pc and you will add those ssh keys here okay we will need a repo to start from  here i have got repositories or repose   and i have got the repo get dash easy this is the repo and i want  to clone that here get clone grip path so this is the command and from  from the repository code ssh i need this path   inside our folder right click get bash here right i am in this folder my current path  is this git dash test all right so get clone right click paste enter we are cloning remote repo locally and it is done now we are inside this repo we have got the command get add period  for that let's create a file here doc1.txt document one save close right click get bash here get now i want to reflect these changes here i  want to push this file to this repo but for that   i will need this command git add  then git commit and then get push and then i will mention the branch name   our branch name is main we can create more  branches you can explore branches from here so get add period enter and then git commit dash n and then just added a file enter one file changed one insertion create mode  this one and now we'll have to push get push origin branch name git push origin and branch name is main enter done reload and as you can see this file is here  doc1 dot txt with the text document 1 with the commit message just added a file so to push changes i need to use git add  period and then git commit and then get push   we can pull changes as well let's say another developer changed  this file like i can edit it from here file was changed by another developer save now this file is like that here file has changed  this text is here that is not present in our file   i want to pull changes for  this file from remote repo   in my local file how will we do  that we will use get pull origin main get pulled region branch name  right so branch name is main enter okay so let's see and as you can see the changes  have been copied here locally from remote repo right so we have used git add git commit get push  get pull and let's see what is this git branch get branch so it will tell me the branch  name current branch name that i am working in and then get branch new branch name let's  create a new branch get branch branch name dev2 now let's use git branch and it will tell me   the current branch that i'm working with  that is main with this static it means that   this is my current branch and we have got more  branches in system that is dev2 and get branch dev three now get branch to  see branches we have got main   dev2 that three we have got three two branches  and one main branch now and get branch dev get branch to see branches dev dev 2.3  main right and my current branch is main   and check out checkout is to switch branch   now let's see if we've got the branches  or not refresh the page reload the page and i don't see branches here so where are  those branches we'll have to commit the changes   and push the changes we've got a command  here git status let's try this git status   on branch main your branch is up to date with  origin main well main branch is up to date and git add period git commit dash m created new branches enter all right nothing to  commit get push origin main main is branch name everything up to date and let's see now reload and i still don't see branches here but if i use this command here git branch it will  tell me that i have got a branch name main and   we i have got a branch dev and then dev2.3 all  right then we'll have to switch the branch get   checkout get checkout dev we are switching  the branch now git check out branch name enter and it said switched to branch dev okay now let's refresh the or reload the page still no branches here okay so git branch  and now it says that my current branch is dev   locally and i've got these  branches okay so git add period git commit dash m add branch dev this is just the message and git  push origin now i am pushing changes to   branch dev so i will not use name main here i will  use dev now the dev branch is being pushed enter okay reload and now you can see two branches  dev is the branch here okay   so for this branch for dev  branch let's add another file and the file is dev this is dev branch this is branch named dev  save now git status it says that we have got   this new file that need to come to be committed  and to be pushed so get add period git commit   added a file enter get push origin dev we push this branch again and now let's use git status nothing nothing to  commit working trick clean and now get branch   it says that i'm in the dev branch and i've  got more of these branches here these two   local and this this is what this one this  one is local and remote as well so reload so i am in the main branch right  now right so let's switch to   dev here in the dev you can see this  dark one and then this dev dot txt here dev dot txt this is branch named dev right now here's the thing i am going back to main  branch main branch hasn't got that def.txt right   this file dev dot txt isn't in the main  branch let's switch back to main branch get bronze bronze information i am in  dev let's switch git check out main git checkout branch name so i'm going  back to main branch named as main enter   and switched to branch main now i'm in the main git branch and it tells me that i'm in the main   and you can see that dev file  has disappeared from here right let's switch back get check out   dev now let's go to this dev branch enter  and as you can see this file appeared here so now we are in the dev branch right so to  create these two branches these two more branches   will have to push these as well git check  out main now i am going back to main branch   and as you can see that dev  document disappeared get check out dev2 now we will create these two branches  okay get check out dev2 now this is   get branch now we are in dev 2 but depth 2 is  not here remotely we don't have dev2 right here we don't have dev2 here okay so let's let's get   can we push it directly get push origin  dev 2 it means that we are pushing this   dev 2 branch that we are in locally  and we are pushing it to remote repo and it was successful and as you can see dev2 is here so for now  we are in dev2 so let's create a document   dev2 dev2.txt this is dev to branch okay can we push again directly everything up to date dev 2 reload but it is not up to date dev tool see  doc 1 we don't see dev 2 text file here   this dev 2 text file so get status and it says  that dev2.txt is here that needs to be pushed   so we will repeat that process get add git  commit get push git add period git commit dash m for dev to branch this is  just the message and then   get push origin dev 2 git push we are  pushing the current changes to dev 2 branch enter okay reload for dev2 and you can  see dev2 document has appeared here   okay so now let's switch back get check out we're  switching the branch okay get check out main we   are switching to the main branch hit checkout  main and now we're in the main branch as you can   see dev2 document has disappeared basically now  these branches are mirroring this is remote branch   now this is main when we checked out from here  this location is now mirroring this location git branch as you can see i am in the main  branch so main branch had got these contents   right so we have got main branch  we've got dev2 and dev we need to   uh populate dev3 branch here now main  dev dev 2.3 let's create that three git check out dev 3 now we are switching to  dev 3 branch switched to branch dev 3 get branch it tells me that we are in the dev 3 but  dev 3 has not been created here right now dev 3 is   at local you see there's no dev 3 here all right  so now we're in dev 3 let's create a document here   dev3 dot txt this is dev3  okay so get add get status changes to be committed new file.3.txt git  commit dash m and here is just the message   edit new file for dev three and  now git push origin dev three so we are pushing dev three branch to remote repo let's see reload and we have got depth 3 here and as you can see  dev3 document is also here right now this is f3   this is dev2 with dev2 document and this  is dev these are our branches with the   dev document this is our main or master branch  or default branch and also we can compare and   create pull request for main branch basically you  create the branches different developers can work   in different branches and then from those branches  we can create pull requests for this main branch   final changes are merged  with this main branch right so get status get branch what branch we are in and we're in  dev 3 and we have got these branches all right   so we have to try this command yet   if we want to create a new branch and we  want to switch immediately to that branch   then we will use this dash b flag git checkout  dash b branch name new branch name new branch name so let's go back to branch main get  check out we are switching to branch main get status get branch where in branch main and now we  are creating a another branch git checkout   dash b dev 4 now the dev4 is  not here locally and not here   at remote repo we are creating it and we  are with dashb flag we will be immediately   switched to this branch when it will be  created enter and this branch was created and switched to a new branch  dev4 kit branch let's verify   and we're in dev4 but therefore is  locally therefore is not pushed yet here   but it exists locally to push this branch we will  have to repeat the process git status git add get status get commit dash m no no branch get push origin dev4 so push this  branch to the origin with the named f4   and now this branch was created reload it was  created remotely as you see therefore is here so get check out main that is our main  branch we are switching to main branch git checkout dev and as you can see dev document appeared here   git check out dev 2 and as you can  see dev2 document appeared here git checkout main and this document  disappeared so all of these branches   are kind of these are versions of this branch  and you can switch to these branches you can   work independently in these branches and then you  can merge any of these branch with the main branch   this is the benefit of version control system  and git and you can use terminal or git bash to clone repo to stage changes to commit  changes and to push the changes to any of   branch that you select and you can pull  the changes and you can create you can   check the current branch and branches  that exist currently for your repository and then you can create new branch  with git branch new branch name   and you can switch branches with git checkout  branch name and you can create a new branch   and switch to that branch immediately with  this command with this dash b flag and git   status will tell you if there are changes to be  committed or files to be pushed to remote repo this is how you use git and command line utility   to clone repose to create branches to switch to  branches and to push changes to remote repository   that's it for this video i hope you liked it  if i missed anything comment down below if you   haven't already subscribed subscribe to this  channel and hit bell icon to receive updates   join us on social media links are in the  description below stay tuned for more updates   i will see you in the next video thank you
Info
Channel: WebStylePress
Views: 50,788
Rating: undefined out of 5
Keywords: git checkout, git add commit push, git commands with examples, git clone, git add command with example, git commands, git status, git add command, git add, git commit, git commands tutorial, git pull, git commands for beginners, git push, git branch, github commit, git tutorial, git tutorial advanced, git tutorial windows, git add repository, git basics, git basics for beginners, git basics tutorial, Git tutorial for beginners
Id: xnR0dlOqNVE
Channel Id: undefined
Length: 29min 39sec (1779 seconds)
Published: Wed Jan 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.