Git Complete Course with Github and Bitbucket 👍🔥

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in this tutorial we are going to learn all the concept of kitkat commands installation and the configuration with the remote repositories an actual example with the bitbucket and github so let's get started please subscribe like and hit the bell icon to get the instant notification when i upload new tutorials what is kit and why it is so popular now if you are someone who is new to programming or is still using a old version control system like cvs or svn then this tutorial is for you those who are new to programming might be wondering what is version control and why do we need this actually the version control system keeps the track of every modification to the code and save it to a spatial kind of database called repository repository not only save the code but also records the entry information like date of code change and the developer who made the changes and the reason why it was changed and some other more internal information let's say you don't want to use the version control system as a developer one you are keeping three version of code in your local system so you are keeping multiple copy of the same code with minimal changes in different versions and then it becomes more complex when you have a multiple developers in a team then it is nearly impossible to sync up the code which leads to unnecessary bugs while merging the code with version control system we can track the history of the code changes and it is easier to work together in a team there are two types of version control centralized and distributed centralized control version are based on the idea that there is a single central copy of your project somewhere on the server and programmer will do their changes on this central copy so centralized version control solve the problem of keeping many copies of files on a drive manually like cvs or svn are the example of centralized version control in 2005 the idea of distributed version control become popular so in this developer each developer clones a copy of a repository and has a full history of the project on their local drives this may seems to be redundant and wasteful but in reality it is not most of the code files are text file which are very small in size and gives a full control to each developer to work separately on their piece of code and later it can be merged into the remote most popular version control systems are kit mercurial and buzzer out of these git is the most popular version control system and we are going to work on git so why git is so popular git is a free open source distribution version control system designed to handle everything from small to very large projects with speed and efficiency it also handle your security with cryptographic method sha1 this algorithm manages your versions files and directory securely so that your work is not corrupted at all git is created by linus starward the man who developed and wrote the linux operating system the very next question it comes into your mind why should we learn it right so almost all the organization in the whole world are using git as their version control system suppose if you are looking for a job in a software development then you must know it it is very likely that in each job description of a developer it includes kit no matter what technology or language you are working on so how do we picture git in a whole sum at very first layer we have our working directory and you can say your workspace so once you are done making changes you add the code files in git which is basically placing the code files in a staging area so once your code changes are in a staging area then you commit your changes by writing some comment so that later you know why did you made those changes it is kind of a hint after commenting your changes these will be recorded or saved in a local repository with some hash address to be unique finally when you are ready to push your changes in remote repository then you push your changes and now we have your changes in a remote repository other developers can see your code now when other developers want latest course from the remote they can just use pull to bring the latest quote in their local repository and from there it will be pulled all the way to the developer working directory or you can say workspace all these three steps are at local system or you can say add a developer local machine and a remote system could be on a server or any git provider main prominent git providers of remote repositories are github bitbucket and gitlab out of which we are going to see github and bitbucket so at first we are going to discuss about git at local system and then we will see about a remote repository as well to work on a kit at local system level you need to install the git in your system first you can directly go to the git hyphen scm url and download the git setup and install it or you can go to google and search for git download and click the first link of get iphone sem.com here you got option to download kit for mac os windows linux operating system for me it is windows so it is showing download right here let me download it once downloaded install it and open the git bash in your machine it will look something like this now type git version and enter bingo if you see the git version then git is installed for linux operating system you can install the git by running these three commands update the package install the git and verify the git version if git version comes up then get it installed for mac operating system you can install brew first if it is not already installed then install git with pro and verify the git version this is command line interface for git operations do we have any gui tools for get oh yeah we do have many and there are some of the examples git cracking source 3 toyota skate and get ui git ui is already installed with the kit setup let's go to git hyphen scm and here click on this gui option here we have third party gui tools we have source free this is available only for mac and windows we also do have github desktop for mac and windows tordicekit is only available from windows now here we have a winner get kraken this works on all the three operating system linux mac and windows and we have other options you can go through here you can check for specific os for android and ios as well why do we need to learn cli if we have gui tools right if you know cli then it will help in your technical interviews to answer the git command questions and certainly they are not going to ask about the gui tools and also if you end up in a project or company where gui tools are not available which is the case actually then cli is your only friend which will help you in all the cases git have three level of configuration first one is system system level configuration is applicable across the entire machine which covers all the users of operating system and all the git rippers next is global configuration global configuration is user specific and it applies to an a specific operating system user now the local configuration is very very specific and is is specific to a particular gate wrapper order of priority of configuration levels are like this system global than local local have the highest priority enough for the theory let's do the git configuration and start with the commands open gate with the administrative permissions in case of mac and linux configuration should be with sudo command so we have opened the git cli let's start with the system level configuration git config hyphen hyphen system user dot name and in the double quotes dev space says because of the space we kept the name in double quotes enter the next command will be get config hyphen hyphen system user dot email so succumb code at the right gmail.com let's check system level configuration now git config hyphen hyphen system hyphen iphone list you can see user dot name and user dot email is being set let me clear the screen clear enter you can also check a specific configured element like git config hyphen iphone system user dot name enter here you can see devices use upward arrow last rand command will appear edited user dot email now you can see the email address now to check all the properties of system level configuration you can use show origin command use upward arrow here we will edit the command hyphen iphone list hyphen iphone show hyphen origin enter you can see all the configuration of system level here let's do the global level configuration now git config hyphen iphone global user dot name double quotes dev space global enter use upward arrow now change this command from user dot name to user dot email type your email here enter now to check the global level configuration we will type git config hyphen iphone global hyphen iphone list as we can see user.email and user.name has been set let me clear the terminal clear enter let's do the local label configuration now git config hyphen iphone local user dot name double quotes dev space local double quotes enter oh we see an error you know why because we discovered earlier that local level is specific to a repository so for that first we need to create a repository or in terms of git that we need to initialize a repository so i'm choosing some place to create the repository for this i'm going to d drive inside d mkdir hyphen p so i'm gonna create a new repository called repositories inside this i'm gonna create local repository that's it enter let me clear this let's type cd repositories local repository all right let's check local repository is blank or not so it is blank now let's create or initialize the kit wrapper here type git init enter initialized empty git repository here let's check what is inside this repository so dot kit folder has been created and as you can see the local repository branch name has been mentioning here as master so by default the branch name is master let's continue with the local level configuration git config hyphen hyphen local user dot name double quotes developer spaced one double quotes same manner we'll set kit config hyphen iphone local user.email support developer at the gmail.com let's check the configuration now git config hyphen iphone local have an iphone list so as we can see the username and email has been set we can also check specific configured element also git config local user.name so developer1 same manner use upward key and change user dot name to user art email so you can see so connellpath.gmail.com is there vim is a default editor for git but git allows you to change your default editor by setting code.editor setting in mac os you can set the emac as your default editor by running this command in linux you can choose nano as your default editor and run this command in the similar way for windows you can configure node plus plus as your default editor by setting the code or editor like this if you are programming on a windows operating system and other developers work on a different operating system you might get into a line ending conversion issue this is because window use 2 corrector for new line carriage plus line feed corrector while as the linux and mac use only line feed corrector which is one so to fix this issue you should set these two properties on windows machine when you get the code from remote repository line feed corrector will be converted into windows crlf if core dot auto crlf is true and by setting the input on windows machine we'll convert the crlf to line feed corrector before pushing your code to the remote repository these configurations are more than enough to start with the gate if there any other configuration will be needed we will set on the fly let's jump into the commands which we are going to use on daily basis while working on any project currently our repository is empty so i'm adding few files here consider this current directory as your working directory or you can say your workspace let's create our first file by using the linuxcat command categor then symbol file name as simple textfile1.txt enter you can write some text here this is a simple text file comma text is okay press ctrl d or command d l is for listing the files so we have our first file created here nice let's create a copy of the sample text file one as sample text file too let's copy one more file as sample text file three tell us for listing the files now we have three files here so all these files we have created are in a working directory level clear command to clean the git terminal ls for listing the files so out of these three files i'm going to add only one file git add sample text file 1.txt this add command basically move the file from working directory to staging area let's verify that by checking the status git status as you see sample text file1.txt is highlighted in green and above line show it is ready to be committed which means it is staged below are the two untracked files which are mentioned in the red it means that these files are still in working directory and not staged clear enter check status again i'm gonna add sample text file too as well but we'll leave sample text file three as it is let's add git add sample text file to dot txt again check the status now the sample text file 1 and 2 are staged but the file 3 remains in the working directory clear enter it is our time to do our first commit now when we commit our files these files will move from staging area to the local repository let's do git commit hyphen m message sample text files to commit enter now our files has been committed let's check the status again git status only the sample text file 3 is shown as untrack files ls for listing the files now we are going to check the log of kit because it shows the history details or you can say the entry details so let's do the git log enter this is the commit hash we discussed earlier and current had branches master this is the author name and the date timestamp along with the comment we have placed while committing alice for listing the files now i'm gonna add all the files which are remaining in the current directory so for that git add dot this dot means that all the files in the current working directory will be added let's check the status now git status you see sample text file 3 has been staged committing this change git commit hyphen m adding sample file 3 check git status again now working 3 is clean now i'm gonna check to log again git log enter here we have two sha hash these are the two changes which are saved in local repository clear enter ls to list the files i'm gonna use the vi editor to make changes in the sample text file1.txt dot file updating save the changes now do get status again this shows our file is updated clear get the status again now here we are not going to use add command but the stage command to put our file to staging area let's stage this file git stage file name enter get status again nice the file is staged now commit this change git commit hyphen m file update enter git status now we have a clean working tree clear enter git restore restore basically means when you bring down the file changes from staging area to working directory or you can say unstage files ls for listing the files i'm going to add it sample text file to so vi sample textfile2.txt updating file2 save it now check the status git status let's stage this file git stage sample text file 2.txt again check the status file is staged now after adding the file to staging area we realize that this file changes are not required at this moment then what do we do with this file so we restore this file meaning we unstage this file let's write git restore hyphen hyphen staged sample text file to git status file is unstaged now but still the file changes are present in the current working directory we can discard these changes as well let me show you by using the checkout command which means that we are going to pull this file from the local repository and whatever the version in the current directory will be replaced with the version which is present on the local repository okay now git checkout hyphen hyphen sample text file two dot txt now if you check the status it should be gone completely git status perfect clear enter now we have restored the file completely let's move on suppose if a b c and d are the git commits and head is pointed to d now if you use a git reset command then git reset will move the head and the branch reference to the specified commit which means if i want to discard the commits of c and d which i no longer need it then i can move the head and point it to b so once the head is pointed to b c and d will be lost let's see the git reset command in action ls for listing the files i'm gonna update sample text file 3 with the va editor now here updating dot dot dot i'm going to save this file and check the status git status file is modified let's stage this file with the help of git stage command git stage asterisk or star which means all the files in the current directory will be staged git status again as we can see file is staged now let's commit this change git commit hyphen m updating file three check the status again now working tree is clean let me run the git lock command enter here we can see the multiple sha-1 hash i want this hash to be my new header and ignore the changes in the above hash so get reset hyphen hyphen soft sha hash this one enter again do the git lock bingo the above command is gone as we have used the soft reset so comment has been removed but the file changes will remain in the staging area so let's get rid of these changes by using the restore command git restore hyphen hyphen staged sample text file 3.txt enter git status now the file has been staged let's discard these changes completely so i'm going to check out the file from the local repository version so git checkout hyphen hyphen sample text file 3 dot txt let's check the status again nice changes are vanished now we have checked the price in the soft hard and mixed earlier we used to check git status for a particular file whether that file is staged or not but how we can know all the file present in the staging area git ls hyphen files will tell us all the files present in the staging area let's see that in action ls for listing the files now let's rename a file mv sample text file 3 to javascript file dot js list the files again these are the files in our working directory now i'm gonna list the staging files git ls hyphen files as you can see stage files are sample text file one two and three whereas in working directory we have javascript file sample text file 1 and 2. so this is how we can know what are the particular files which are staged let me add the files git add dot let's check the status again so file has been staged as you can see it is saying renamed so kit is smart enough to recognize these things now i'm gonna check stage files again git ls hyphen files so as you can see the javascript file now staged ls now i am going to remove sample text file to dot txt rm sample text file 2. txt let me add git add dot let's check the status again beautiful we can see that the file has been deleted and another file is renamed let's commit these changes git command hyphen m removed file and rename get a status our working tree is clean now let's move on git stash is a temporary place or shell where you can move your files from working directory or staging area so that you can quickly switch and work on something else as you were in middle of coding one thing and cannot commit your changes right now and also you need to work on a new requirement so in these kind of scenarios stash becomes really handy let's see it in action ls enter i am going to copy javascript file.js into type script.js ls again now i'm going to copy one more type script file as typescript 2 now ls again i'm going to check the stage files also so git ls hyphen files so type script and type script 2 are not staged let's check their status i'm going to add these two files check the status again these two files are staged at this particular point you came to know that these changes should be on hold and we need to make some other changes and later we need these changes again so by using the stash we can handle the situation so i am going to stash these changes git stash save type script changes enter let me clear the terminal clear enter to know how many stash do we have we should use git stash list enter now we have this stash available so our two type script file changes are stored in this stash so now if you check the status again you won't see those changes let's do the gate status as you can see there are no changes in the staging area and working tree is clean let's check the current directory ls and also in the current directory you don't have your changes so as the changes are staged i need to work on something else so i'm going to edit the sample textfile1.txt so here some new code changes updates save it list the file again and check the status now this is the point where you need our stash changes so now we need to bring back those changes let me first list the stash git stash list then we need to apply this stash git stash apply and this dash index number enter nice we see the stash changes were already in staged area so it came back like that let's stage the sample text file one as well git stage as trick get status all files are staged now i'm going to commit these changes now git commit hyphen m changes updated and added clear enter list the stash again git stash list so we have utilized the stash already then we can remove this dash right we need to drop this dash get stash drop and this is the index office enter and get stash list again now we can see that there is no stash available in the list right now we have done git stash apply and drop in two steps we can achieve the same scenario by using git pop command let's see the example ls copying sample text file 1 2 sample text file 2. ls let me add these files git add dot check the status again now the sample text file 2 is staged let me stash these changes git is save new file clear enter let me stash the list get stash list stash is present so let me check the status again get status our working tree is clean now let me apply the stash again but this time we are going to use stash pop command which will do both applying and dropping the stash let's do that git stash pop stash at the rate 0 index enter as you see the stash has been applied and the stash has been dropped check the stash list there is no stash is available now let's commit these changes git commit hyphen m pop changes test enter now we are done with the stash let's move on branches are the pointer to your main code base and allow you to create another copy of code base with all the code and history suppose if you are working on a new development item on version 3.0 and at the same time another developer fixing a bug for version 2.0 in these kind of scenarios branching will help us to continue the work for both development and bug fix let's say this is your master branch you create another new branch from this as new development and another developer will create a branch called bug fixes for version 2. as soon as the bug fix is done it will be merged into master and later you can merge your new development branch into master once your development is done actually the branching offers a way to work on a new feature without affecting the main code base that's why the branches are the part of everyday development process let us understand this with an actual example let's go to command line currently we are on a master branch as you can see here how can we check how many branches do we have presently git branch enter we have only master branch right now let's introduce one more branch so to create a new branch we need a command git branch and the name of the branch in this case new branch now check the branches again git branch enter we have two branches one is master which is highlighted in green meaning the master is active branch which we are working on let's switch the branch to new branch git checkout new branch enter new branch is active now let's check how many staged file we have on this branch git ls minus files enter we have five files let's also check the git log git log enter here you can see that the head is pointed to new branch as well as master branch because there are no changes in both the branches clear the terminal grid branch now list the files i am going to remove javascript file dot js rm javascript file.js enter now i'm going to add this git add dot let me check the status git status as you can see that this file is deleted let me commit this git commit hyphen m javascript file deleted enter let's check the status again so after making changes in this branch i'm going to move to the master branch git checkout master enter let me clear the terminal git branch now i'm going to merge the new branch into master so git merge new branch enter as you can see that javascript file dot js showing one minus so this is the deletion in the new branch but when we merge into the master these changes will move into the master as well let's check the status so working tree is clean now let's check the log git log enter so we are in the master branch but if you see this commit we have done this in new branch so during the merge not only the code but also the history will also merge the another way of creating a new branch is git checkout hyphen b and the new branch name so here new branch 2 enter so as you can see that new branch 2 has been created and also it has been checked out which means that we switch to new branch 2 from master list the files ls now i'm going to edit the sample text file too so vi sample text file 2 dot txt enter so here i'm going to write new code changes let's save the file and stage it get stage as trick now i'm going to commit this git commit hyphen m updates enter now after making the changes into the new branch 2 i'm going to the master branch and in master branch i'm going to make the changes on the exact same file and on the exact same line let me do that vi sample textfile2.txt enter now here i am going to make changes on the same line changes in master why am i doing the changes on the same line you will get to know in a moment let me add and commit at the same time git commit hyphen am changes in master enter oh double quotes enter commit is done let's check the log git log enter as you can see the head is pointed to master i'm going to clear the terminal clear enter get branch now the current branch is master and i'm going to merge the new branch 2 into master so git merge new branch 2 enter now wait here we can see that auto merging has been done but it failed in between and it has some conflict right so if you remember that we have made the changes on the same line exact same line then we end up with this issue which means conflict so you need to resolve this conflict manually let me go and fix this git status let me edit the sample text file too now if you see here we have arrow symbol with head which means that this arrow head and then the equal equal symbol so whatever in between this which is code changes in master it means that this is present in the current branch which was master in our case and below the equal equal line and the arrow head with new branch 2 this means that this is in the new branch 2. so these changes are on the same line so we need to decide whether we need both the changes or we need one so in this case i am going to keep both the line while resolving the conflict we need to remove these extra lines let me remove it perfect now we can save this file and commit our changes now git commit hyphen am conflicts fix enter so commit is done let me do the git log as you can see the head is pointed to master so we had two changes after we have made the changes in new branch 2 so you can see that changes in master and conflict fix are the two commits we have done after the commit of new branch 2. so that's why the head is pointed to master which is ahead of the new branch too so let me show you the file ls cat to show the text sample text file two dot txt enter beautiful file contains both the lines as expected let's clear the terminal list the branches again git branch enter now as we have utilized all the changes inside the new branch too so we can drop this branch so git branch hyphen d new branch to enter deleted branch so let's check again git branch enter so the new branch 2 has been deleted alright let's move on let's set up the remote repositories now github account setup you can directly go to this link github.com or you can go to google and search github now you can click the first link getup.com github is the most popular and widely used remote repository so no doubt it is a number one git provider and it's been trusted over 50 million developers and three million organizations with over 100 million repository github repo are being used by big as well as small organizations and even the individuals are using it so as you see here ford kubernetes spotify and adobe and many other organizations are using it let's go to the top and click on sign up we button redirected here now let's fill the information for username i'm going to type succun code for email address let me type sucooncode there gmail.com enter the password now scroll down so here for verifying your account click verify it says picta spiral galaxy so click on this one i don't need any emails or announcement or updates so uncheck this if you need you can check it but i'm not going to need it so now click on create account as you see here it is saying selected plan is free so we are not going to pay anything to get up let's answer these questions to set up the account accordingly what kind of work do you do mainly so i'm a software engineer so i'm gonna choose this one next question is how much programming experience do you have so i have a lot of experience so i'm going to choose this one what do you plan to use gita for create websites and get up pages learn kiran github and host a project now here you fill your interested language and the frameworks so let me write java javascript python html and css as well and last sql let's click on this complete setup okay so here it is asking please verify your email address and github already sent an email so let's go to the gmail open this email click on this verify email address your email address is verified this is your notification box let's click on this github cad symbol and go to home so we are on the home page now it says create your first repository so we are ready with the github account setup now let's go and create the bit bucket account setup now you can directly go to the link bitbucket.org or you can go to google and search bitpacket and click on first link bitbucket.org bitbucket is a product from atlassian it provides free git repository for a team of five people and here other products are mentioned of atlassian so let's go and sign up click on this sign in button and now click here sign up for an account we are redirected to the sign up page here i am going to type my email address as such developer gmail.com and type the name sucoon developer and now let's enter the password click on sign up now bitbucket signup is finished and they have sent an email to verify our account let me go to my gmail so developer gmail.com id click on this email and click on verify your email it is asking to provide username let me copy the email id and remove this at gmail now it looks good click on continue you can answer these questions or you can skip as well i'm going to answer these question for first question you can say i have no experience for a second we have choose one to five so choose this one and describe your role so you can choose as a student and you are doing this for learning get now submit it so we are ready with the bitbucket account setup now now let's go and do the configuration of git remote repository for both github and bitbucket now that we have created accounts for github and bitbucket it's time to do remote repository configurations so first we will do the github remote configurations let's go to github home page so to create your first repository on github click on create repository let's put the git tutorial as a repository name in description i'm gonna mention git tutorial in detail scroll down and let's click on the create repository we are redirected to this page on this page we have our git url for the git tutorial repository so let's copy this url by clicking on this copy icon now let's go back to our cli git terminal here i'm going to add github url as remote repository so git remote add github and here let's paste the copied url now enter so github remote repository configuration is done let's go ahead and do the configuration for bitbucket let's go to bitbucket home page here click on the create repository let me mention the project name as git project and repository as git tutorial i want this repository to be public so unchecking this and change this to no and this also to know as i don't want readme or git ignore file as of now now click on the create repository in this page we have few information but now we only focus on the git url of bitbucket let's copy this url now let's go back to the git terminal here let me add the bitbucket url as remote repository against bitbucket name so git remote add bitbucket and paste the bitbucket url here now enter so bitbucket remote configuration is done let's verify these remote url configurations git remote show github this is the name against which url is mapped enter awesome a configuration url is present here let's verify for the bitbucket as well git remote show bitbucket enter perfect this is also present here after configuring the remote repository url we need a way to upload our local repository content or files to remote repository so for that we have a command called git push with the help of kick push we can transfer files from local repository to remote repository in our case it will be github or pit bucket important thing to notice about git push command is that you can only push committed files while you upload your files to remote repository you need to be very careful because it can overwrite the current files present in the remote repository so let's understand the git push command with an actual example let's go to command line so at first let's upload our files from local repository to remote repository with the help of push command git push bit bucket master let's understand this command git push means uploading your file from local repository to remote repository bitbucket means that you are choosing a bitbucket account which is mapped against this name after this name we have a master so master is the name of the branch so you need to give the branch name here given as master let's enter okay now this is our first time to push our code into remote repository so we need to provide the password for bitbucket account so let me enter the password now enter your files has been pushed go to bitbucket website let me refresh this page bingo we got our local files here so as you see we have our sample text file one two and javascript javascript to dot js let me open this file one you can read these files click on this here you can see the git logs with all the information you have author name commit id message and date let's check the branches click on this right now we have only master branch let's go back to the command line let me clear the terminal it's time to push our code into github repository as well it is exactly the same process as we did for the bitbucket only the name and the git url will be different so let's enter git push github master github git url has been mapped with this github name press enter as you can see the code has been pushed successfully let's go to the github page and check whether it is really there or not so let me refresh this page bingo we got our files here let me open this one sample text file one so here you can see the text as it is a text file let's go one step back to git tutorial let me show you the branches so here it has only master branch and right here you can also check the commits you can go through these all options and explore a bit more here so this is the way of uploading your file from local repository to remote repository now how do we download our code from remote repository to local repository for that we have a git pull command git pull command is basically to download the content from remote repository and update the local repository to be more precise it merges remote upstream changes into your local repository let's go to github website here i'm gonna add a simple text file1.txt click on edit here let me write updating directly on remote repo scroll down a little bit in git ui we have option to directly commit our changes so let's put our command here updates click on comment changes so changes are committed now now click on git tutorial to go back our commit number increased from 10 to 11 click here to check the git logs this is the change we did 13 seconds ago with the username as cone code and these are the previous comments we did in a local repository as a developer one let's go back to gate command line check the status git status here we are going to use pull command to download the latest changes in this case we have made the changes directly on the github remote repository so type kit pull and this is from the github so github branches master enter as you see here one file changes and one insertion is there list the files ls enter now here let's check the content of the sample text file one so cat sample text file one enter so we have our updated line updating directly on the remote repo let's clear the terminal clear enter let me show you one more thing i'm going to pull or download file from bitbucket now let me try git pull bitbucket master it say it says update it already right so whatever the changes present in the bit bucket remote repository is already present here let's check the status again so our working tree is clean let's go to bitbucket remote repository here we are going to add it simple text file to click on edit let me type bitbucket remote changes here now click on commit put your commit message here click on commit now so our changes are committed let's go to git commit history click here on commits as you see the author name is socon code so this is the username present in the remote bitbucket and it takes default username as the author name so let's go back to the git terminal let's try to pull the latest changes from the bitbucket here and get pull pit bucket master enter now it is asking to merge the remote changes into local repo so this is what the pull command does right in the background so in this case it is actually merging the remote changes into the local repository so we have made our changes in local repository that's why it is asking to merge so let's save it file is merged into the local repository and it says one file has changed and one instruction is there so let me list the files ls enter we have made the changes in sample text file too so let's check the content cat file name enter so bit bucket remote repo change is there git clone git clone command is a git utility and we use this kit clone command to copy an existing remote repository into a local system so to understand it better let's take an actual example let's go to github remote repository let's go to the git profile page to create a new repository click on repositories click on new button so let's give the remote repository name as mobile app and go to description here i'm gonna write detail description and i will leave other settings as it is and scroll down now here click on create repository repo is created let me add a file here click on this i'm gonna say this file as main.html and let me paste some html and javascript code here all right scroll down now put your command first commit for mobile app click on commit new file so now we have a file here to clone a repository click on this code and click on copy icon now github url has been copied let's go to git command line we are already in a git repository let's go to somewhere else and clone this repository so cd dot dot to go one step back now do the git status here so we don't have a git repository here let me make a directory mkdir new repo enter now cd new repo here i'm going to clone the github mobile app repo git clone hyphen b branch name is master we are copying from the github so github url is there enter we have successfully cloned mobile app here let's go inside this ls cd mobile app bingo we got our git repository here let me clear the terminal clear enter list of files ls enter we have only one file here as we expected let me copy main.html to app.js enter ls again now we have two files let me commit these changes so git commit hyphen am new file changes enter oh app.js is not staged yet let's do it get stage asterisk check the status again as we see file is staged so let's commit it git commit hyphen am new file changes git status again now our working tree is clean let me push these changes git push enter let's go back to the github refresh the page now our changes are present so we have seen the example of git clone command with github now i want you to try the same example with bitbucket and if you need any help with that then please comment or you can email as well let's move on git rebase get rebase is a process in which we combine our sequence of commits into a new base commit which means that with the help of get rebase we can maintain a clean working history clean working history will help us in understanding what changes has been done in a proper sequence which ultimately will help us in finding the bugs in case of any error now let me take a pictorial example to get you the understanding what actually the rebase do suppose you have a master branch with c1 and c2 commit now from this master branch we create a new branch called feature branch now in the feature branch on top of c1 and c2 commit we make a new commit called f3 after some time someone else made a change in master branch called m3 commit so when we merge the feature branch into the master the m3 command will come first then f3 command will come in reality the f3 has been committed before and sequence will be distorted if we merge these two branches but if you need a proper sequencing then you need to rebase it so what exactly happened after ebays is this c1 commit will come then c to commit will come then f3 then m3 commit so this is what the proper sequencing is let's understand rebase with an actual example let's go to git command line here first we will check how many branches we have so git branch enter we have active branch master and this is the only branch we have now let me create a new branch called feature branch so get branch feature enter let's check again git branch enter we have two branches now let's check out the feature branch git checkout feature now we are in the feature branch as you can see here let me show you git log as well git log enter we have only two comments let me clear the terminal list the files i'm gonna copy main.html to panel.html enter now add the file git add dot i'm gonna commit now git commit hyphen m feature iphone zero one commit enter changes are committed let's check the get log now now we have a new commit feature zero one commit clear enter list the files again ls enter i'm going to change the content of main.html so vi main.html enter here i'm just changing the heading h2 to h3 and here let's say javascript changes updates save the file list the files again ls enter now i'm gonna stage all the files get stage asterisk enter now i'm gonna commit git commit hyphen m text updates now let's check the log again git log enter here we can see that the latest commit is text updates and after that feature 01 commit so now we have made two changes in the feature branch let me move to master branch and commit one more change then we will do the rebase so let me check out the master branch git checkout master now we are into master branch check the git log now we have only two comments here let's make some changes ls enter copy app.js into sideband.js enter now list the files ls enter we have three files now let's add those git add dot oops we have an error here let me do it again git add dot now commit the changes git commit hyphen m master hyphen zero one the status again our working tree is clean now let me show you the git log again latest commit is added clear enter now wait so what exactly we have done so far we have made two comments in the feature branch and one in master branch now if we merge the feature branch into master your feature brand changes will be the latest change and which is not the case so we need to ensure that we have a proper sequence history in which the operation has been performed so for this particular reason git rebase comes into picture to achieve the proper sequence of git log or history so let's rebase the feature branch into master git rebase feature enter now feature brand changes came into master with a proper sequence now are you excited to see the catalog let's go there git log enter nice the master hyphen zero one is the latest commit we did in the master branch and then the text updates commit with it and then the feature zero one in this case all the sequence are coming in a proper order and you can also see the timestamp this is at 20 42 20 44 and then 2047 so commits after rebase are in sequence now clear the terminal let's check their status again now we are going to push this into github so git push enter let's go to the github and see our changes here our change is updated go to commits now if you see the history here this is what exactly the proper sequencing is why did we focus on the clean history right so in real time the clean history or a proper sequence help us to identify the box and to roll back on a stable version of the application so now we have understood the get rebased command let's move on git ignore is a special file to track all the files which needs to be ignored there is no explicit git ignore command instead of that we need to edit this dot kid ignore command and add the type or the extension in this file let's see this in action as it is very easy to understand with an actual example let's go to github remote repository we are working on mobile app right now so choose this one click on mobile app here i'm going to add git ignore file click on add file and the file name should be exactly like this dot git ignore and inside the body of this file we have to mention what are the files which you need to ignore so i'm going to ignore dot log file dot class file and dot pdf file here the asterisk represents any name of the file so it could be xyz dot log file or anything let's uh comment this file scroll down i will leave this command as it is create.ignore file now click on commit new file your file has been created click on it so these are the three type of file which you are going to ignore let's go to git command line and pull this change git pull enter check the files ls enter oh where is our kit ignore so as this is a dot git ignore file it is a hidden file so let me show you ls hyphen a here we have our get ignore file now let me copy this app.js to app.log and now copy the main.html to main.pdf copy this panel.html to panel.class all right ls enter we can see our files are there let me add those file git add dot enter now commit this change git commit hyphen m git ignore testing now push to remote git push oh it says everything up to date let me go to github and check refresh this page oh we don't have any change here right so what exactly happened here go back to command line now here type git ls hyphen files enter now if you see here our log pdf and class file has not been staged even so that's why there is no change in the remote repository as well this is how the git ignore file help us to ignore certain type of files which we don't need to push into the remote but still we need those files to run our program now ls enter i'm gonna copy app.js to app2.js okay now add this git add dot enter now i'm gonna commit git commit hyphen m file edit enter now push this change to remote git push enter change has been pushed now check the get ls hyphen files so app2.js has been staged so it should be there in the github repository now let's go there refresh this page we can see app.js and app2.js files are there let's move on when you clone a remote repository on your local system you cannot contribute back to the upstream or remote repository unless you are explicitly declared as a contributor that's because your clone is separate instance of that project and if you still want to contribute to this project you can use the fork git work you might have heard this a lot of time but still it is confusing right actually the fork is not a command but a concept so we already know the git cloning concept in git cloning we copy our remote repository code into a local machine right and similarly in the git fork we copy someone else's original remote repository into our account remote repository so it is kind of a remote to remote cloning but between two different accounts once you have a remote copy of original repo you can clone it into your local machine and update this code now you can push the changes to remote copy from the remote repository you can raise a pull request to the original repo original repo owner can approve or reject your pull request or sometime called as pr let's see the git fork in action to understand it better let's go to github remote repository here i am searching a public repository which i need to fork with the username jack l search in all github now here we have our result jjl typescript.js project click on it this project is under jjac l user and we are logged in as a socon code user so to fork this repo we just need to click on this fork button click on this now github is creating a copy of this repo into your account now copy has been created of this typescript.js project under your account let me copy the git url and go to git command line okay presently i'm in d drive make a new directory mkdir repo now go inside cd repo let's clone the git repo here git clone paste the url enter now go inside cd type script js project enter we are in the main branch now clear the terminal now i'm gonna list the files ls enter we have only one file here now i'm gonna add my code and make this project better so vi console.js i'm gonna add console.log making your code better save it check the difference now state the file git stage star let's commit the changes git commit hyphen m updated type script let's push the code git push enter code has been pushed to remote repo let's go there refresh this page check the content now we have our code here in order to merge this fog report to original repo we have to raise a pull request so click here on this pull request if you see it clearly the arrow is towards the original repo so the update will be merged from sukun code typescript.js project to jack type script.js project as you see we have only one line change let's click on this create pull request provide your comment here please approve it has improved code finally click on this create pull request so pr is open now now let's go to our another account jj and user we got one pull request click here scroll down now this is the pr we need to review click on this so we got an update from succumb code user as it says it has improved the code scroll down click on this merge pull request you have three options to choose from here i'm gonna choose default create a merge commit click again so no conflict as it has only one line chain click on confirm merge now our pr has been approved let's see the code now our updated code line is present here so we have covered git fork and when this is good enough for our senior programmer to work on any project i have covered all the necessary commands and concept to give you a full understanding of it congratulations you have completed this tutorial so please subscribe like and hit the bell icon to get the instant notification when i upload new tutorials thanks for watching the video have a wonderful week
Info
Channel: SkoonCode
Views: 19,047
Rating: 4.9464288 out of 5
Keywords:
Id: eBmG7keE8B4
Channel Id: undefined
Length: 69min 39sec (4179 seconds)
Published: Tue Jan 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.