YTread Logo
YTread Logo

Git Tutorial for Beginners - Git & GitHub Fundamentals In Depth

Jun 09, 2021
Hello everyone and welcome back. In today's video, what I'm going to do is teach the basics of

github

, so basically everything you need to know to use

github

effectively and all the common commands that you'll use 99% of the time. Keep in mind that getting github are extremely complicated tools when you get to the advanced level, there are a lot of things you can do and there are thousands of commands and command variations you can use within git and github, of course I won't. I will show you all those things, if you need to use them, you will look up and use them from time to time.
git tutorial for beginners   git github fundamentals in depth
The things I will show you here are what I can almost guarantee you. I use it literally 99% of the time, so with that being said, what I'm going to do in this video is really focused on trying to teach you how get and github work. I don't want you to just memorize the commands that I want you to actually understand what those commands do, so that if something goes wrong or you need to figure out which command to use, you actually have an idea of ​​what's going on at a lower level. With that said, I'm going to move on to the sort of whiteboard here, where I'm just going to do some drawings and illustrations, we'll talk first about the difference between git and github, then we'll talk about the github workflow, we'll talk about branches, and then we'll get into all the different commands and that will probably be around the second half of this video so I'm here at the whiteboard and the first thing I want to discuss is the difference between git and github so a lot of people seem to think that getting github is one of the same So they are exactly the same, that is not true, they are actually different things, they obviously integrate very well with each other and are very similar and what they really do, but they are two separate things and I think that is important.
git tutorial for beginners   git github fundamentals in depth

More Interesting Facts About,

git tutorial for beginners git github fundamentals in depth...

To understand the difference and github is actually just a website, I like to think of it as some kind of nice plugin or extension to get and what github does is give us a nice user interface and some features that git doesn't have. I don't have it and it allows us to host remote repositories and work collaboratively with many other people. Now what git does is this is actually what handles all version control, so when you do something like merge code or when you do something like make a commit or make a change or pull or push you're using get get is the version control software version control this is what we're really going to learn how git works github is like a layer on top of git that gives us a bunch of commands, gives us a bunch of UI features, has a site fancy web and a bunch of other things you just don't have, so these are two separate things, don't confuse the fact that they are the same and I want to make it clear that we can use git without even having to touch github because github is not necessary, It's not a dependency on get, it's just something we use on top of git and there are many other tools that go on top of git as well, so with that being said, let's now get into the type of workflow when using a github repository and look at how What do I mean when I say the word repository, so let's go here to explain what it is.
git tutorial for beginners   git github fundamentals in depth
I'm talking about repository and through the differences between what we call local and remote repository, which I think is the first thing to understand. I want to consider an example where we have a team of four developers, let's say we have four people and they are working on some kind of game, well what these people probably want to do is they will all have their own machines, they will all be coding and they will want synchronize with each other just when one person finishes. a feature or they make some changes they want to send them to the other person when the other person has some changes they want to send them to them and they want some kind of system that keeps track of those changes and that means that you know everything is going well, so essentially we don't We're sending zip folders between us, we actually have some kind of automated system that's handling this version control for us, so let's say we have our four developers, what I'm going to do is I'm going to draw four boxes here in the corner of my screen and these will be my developers.
git tutorial for beginners   git github fundamentals in depth
Now here we'll draw a big circle and this is what I'll call my remote repository, so a repository is really just a repository. it's a place where we have a bunch of code and it can be remote or local, a local repository is something that sits on your machine so it sits on your end in front of you, other people don't see it, it's yours. version of the code which is a local repository, so each of these four developers has their own local repository on their machine, so let's say we start in development and we're just getting started, there's a bit of code that already exists, first thing What all these developers would do is look at the remote repository, which will be our source of truth.
This will be the place that actually has all the updated code. This is where all the changes go. this is where it starts this is where we have the most recent version the version that's working that's what we think of when we think of a remote repository this is the place that these four developers trust the one that has the most up to date version up to date version and they will make changes in this place and request new changes and that is what the remote repository does. Basically, these four developers have four local repositories on their computer, they are based on some kind of version.
Outside of this remote repository, they will make changes to their local version and then push those changes to the remote repository and when someone else makes some changes, they will delete them, so this is the basic workflow. We have this remote repository. When we start, all of these developers grab a copy of this repository so they say, "Okay, let's copy it to our local machine," so let's say at the beginning, at time zero, all of these developers have the same copy of this remote. . repository now let's say you know that developer one starts working on a new feature, well his codebase immediately locally will look different to developer two and it will look different to the remote repository, that's how it works, so let's say that developer 1 makes some changes. on your local machine you test them, they look fine and what you do is you say, "Okay, let me push these changes to the remote repository." I want my other teammates to see them.
I want to verify it. I want to make sure everything is okay. it pushes those changes to the remote repository now, the next day, it tells the developer: hey, I made some changes, pull them down from the remote repository, what it does is it asks the remote repository, hey, give me any new changes, and then it compares the remote repository. repository with your local repository and it changes everything you changed, so it gives you all these new changes, maybe a new file was added, maybe some files changed lines, whatever it is, that's what get does for us, it pretty much handles the interaction between changes and making changes. that's all it really does, when changes happen it handles it for us and the nice thing about git is that since it's a very complex tool it can do things like merge code automatically, like let's say you and I have worked on the same file, but we changed different parts of those files, well git can actually figure out what happened in those two files and then automatically merge those changes so that there are no conflicts, now sometimes there are, but that's beside the point, this is the basic git workflow and That's what I wanted to cover here, so the next thing I want to talk about is how to get the history and branches.
This is really important and if you can understand this part here, you will be good at understanding like 99% of github or the things that you will actually have to use. All github really does for us is track a history of what we call commits. Now a commit is simply a change that you've made now and it's not necessarily like you change a line of code I wouldn't call that a commit, what a commit is is essentially you make a bunch of changes on your local machine and then You commit those changes, so you say, hey, I want to save all of these changes, I want to group them into their own little package and I want to store the fact that I changed all of these things right now, that's what a commit is essentially like a point of departure. control, a way to go back to a previous point if something goes wrong, so not every time you save the file.
Are you doing a commit? You actually have to commit manually, so let's say I add as a new feature or have a bug fix. I would commit it so that way let's say I messed up something in the future in the codebase, I can always go back to that commit and say hey, right now, this was working, it was working, that's the point of a commit and it stores a lot of data with it, who did the commit, what time the commit occurred and who changed. which files you know when they were changed within each file it stores a ton of different information and that information is really valuable when we start talking about branches and kind of a timeline in github so we have all these commits and the commits are just changes what you do is on your local machine so in your local repository here you know you make a bunch of changes, you do whatever you're doing and then you commit those changes locally so inside your local version from the repository commits those changes once you've done all your commits so you can do multiple commits, you don't do as many as you want, you know, just checkpoints that you just save when you want, essentially, it'll take those commits and send them to the checkpoint remote. repository, then this is your local repository and this would be the remote repository.
Now the remote repository will take a look at all of these commits and try to bring all of those commits and push them to the remote repository's branch, so I haven't talked about branches yet, so I'm trying not to say that word, but basically I imagine that you take these commits and somehow merge them with the existing codebase and add them, that's what happened, it happens when you push commits. Now let's say you're on a local repository and you know that it's been a few days since you updated your repository. The remote repository has changed. People have made some changes.
Well, what do you need to do? You need to get those changes. So what you do is what's known as pulling, that is, pulling all the changes from the remote repository, so let's say the remotes up here pretend that this one is gone, you pull them all in, and then what it does is it gives you all the new commits that have happened since you last removed these changes, you now have all these commits coming from the remote repository and you merge them into your local repository to take them and combine them with the work you currently have and that's how this system works with a bunch of commits, now what github does for us is track all of these commits, so let me try to delete all of this, let's get rid of that too, so in github we have these things called branches and the first branch I want to discuss is what it's known as the master branch now we have all these commits these are all our checkpoints all our save types and we push the commits and we push them down now the remote repository and even your local repository like Keep track of all these commits and everything what happens in the repository, so if at any point something goes wrong, I can always go back to a previous commit or I can just see the entire history and what happened in this code. base that is very valuable, so all these points that I am going to put here are commits and imagine this is a timeline, we are back here, in the past previous commits and right here, at the end of the timeline is what the current codebase looks like and it's the most recent commit, so what stores all these commits in this timeline, maybe they all come from different people, maybe they're all the same person, whatever there are all of them these commits, these are all the changes. that happens now, this is what we call the master branch, so the master branch of our repository is actually what we think of when we think of the codebase, we have a branch and a branch is just a version of this codebase. code essentially and it's hard to describe until I show you what another branch looks like, but imagine that the core codebase you're looking at will almost always be the master branch.
Now this master branch is what we want to make sure is always working. Think that if we are working on a big project, I don't want to modify this master branch with some code that is broken or not working properly because if another developer deletes it now, suddenly their local repositories will be broken because you. I made a change to the master branch, they brought down the master branch and now they are all you know, they areall messed up because you made a bad change to the master branch, so instead of always making changes to the master branch.
So instead of always putting these bubbles and these commits here, sometimes what we use is what's known as another branch and what essentially a branch is is a copy of a repository at a certain point in time that has different changes, like so Let's do this. then another branch might look like this so maybe this branch which I'll call feature is like a new feature so when you have a new branch you give it a name you can call it whatever you want and the point of this branch is essentially to be able to work in a new feature, push it to the remote repository without actually putting it directly into the master branch, so if I make a new branch, maybe I branched starting at this point here, so I branched right now in this commit now this branch has everything the repository had up to this point.
So everything behind it has all those changes and you've branched and now these points here are your changes on this branch, so you're just making different changes on this branch so that you don't affect the master branch until you're. make sure this branch is fully working because imagine you and other developers are working on a new feature that isn't finished yet, you need to work on it together, well you could create a new branch outside of master. branch so that it doesn't affect the master branch of the code the things that everyone else sees and then as soon as this branch is satisfied that it's actually working, that everything is fine, what it does is merge it into the master branch, like so you take all these commits here and you say, well, I want to merge them into the master branch and then do your magic, which I won't really discuss, and you take all these commit messages and you line them up on this master branch in the order they should go and you do all of them. appropriate changes, that's essentially what happens when you have what's known as a branch and again you branch because what you want to do is make sure that you don't modify the master branch until you're sure that what you're doing is working and, of course in this branch here in this feature branch you can still update this branch from the master branch.
What you can do is say, "Hey, give me all the latest updates from the master branch, put them here so this stays up to date with the master branch, but you have some new changes that aren't in the master branch yet, that's what another branch needs to do and you can even branch from branches, so when you get into really complicated projects, maybe you have another feature you're working on in addition to a feature, well, you could branch from another branch, merge it with this one branch, so merge like this and then merge all of this to the master branch, I know, okay, so this was a long explanation of git branches from github, but I think we've gone through a lot of theory, most of it. the theory we need to understand and now it will actually be It's easy to get into the commands and start doing some examples.
That said, let's now go to the terminal and actually go to github and let's set up a repository. Let's look at some examples and learn what these do. different commands. so I'm on github here and I actually just wanted to show you an example of a large repository and what it looks like in terms of branches and commits before we get into the commands, so this is actually the repository that I work on. work so I work at Microsoft this is an open source repository this is the extension for vs code so python four vs code and I just wanted to show you that if you're looking on github this is github the website you can't yet see him. right here this repo has 4500 commits and 22 branches so if I click on commits I have to accept this let's see if this goes over here okay so I'm on commits now and you can see this is what I'm on talking. say master branch and here you can see all the commits that have happened and that have been pushed to this branch so it shows you what day all these commits happened and then you can click on a commit, let me click on one here. and let's take a look at what this is, you can see the things that have changed in all the different files and what actually happened in this commit, so it's really valuable to have these different branches and these commits because you can look back in history of everything that happened in your repository now, if you go to the branches, you can see that there are a bunch of branches here that people have been working on and these are branches that are outside of the master branch, so let me click in my branches and you can see I haven't pushed any branches from the repository, but if I go to maybe active branches, let's see how many active branches we have, we have all these branches that are currently active that people are working on, so that's what what I mean by branches and commits and now I want us to start with our first github repository, so the first thing we need to do is download and install the tool called git.
This will be the same on Mac and Windows. of the commands that I show you, but you must download install git. I assume most of you have this so I won't follow the steps but I will leave a link in the description that has the link to download. and install git once you have it, what we'll do is start by creating a local repository on our machine and experiment with how all that stuff works and then we'll talk about remote repositories, so let me switch. directories to my desktop if I could get there, so I'm at my command line.
CD means change directory. This is a common tool. You'll see me use some command line tools. I'll explain what they do here, but these should. It will be the same on Mac, Windows and Linux too, so don't worry about that, but go into your terminal, open a terminal, open a command prompt and then go to your desktop or go to some location where you can make a new folder and m'kay dirt and the name of your folder, which in this case I'm going to call test underscore repository, so this will be my test repository, this is what I want to experiment with, so I'm going to make a new folder on my desktop, that's what mkdir means, directory called test repository.
Next, I'll see B in my test repository like this and now what I'm going to do is initialize a new git repository, so there are many different ways to type start and you get the repository, the most common way if you're working on a new project and you're starting it on your local machine is that guy, so let's say you're about to start working on something that you know you haven't worked on yet and you're starting the repository, it doesn't exist anymore, what you do is to type get an it and that will make any folder you're in a github repository, so keep in mind that you can do this anywhere, but as soon as you initialize a folder as a github repository, git will track anything inside it and what that means is that you can add files, you can use all your git commands inside this folder, but only if you have initialized a git repository, so let me type git commit and you will see that this works, everything is okay, but if I actually go back to the CD, I go back to the desktop and write the same thing. so let's confirm that it says fatal, not a git repository, so just make sure you're actually on a git repository before you start doing all these git commands.
Ok, I've created a git repository and what I'm going to do. What I do now is I open this in subline text, so I'm going to archive the test repositories from the open folder right there. Awesome and now I'm going to make a new fold, create a new file server, so archive a new file, let's just name this readme file MD and save it inside the test repository and let's make a markdown file, let me hit hello, so it's like a header that I just created in a markdown file, cool, so I have it now and I've made a change to this repository, so let's imagine you know I added my code.
I am in the repository. I made a new change. The first thing I need to do if I want to commit or store this change. I want to make that checkpoint need to add all the files that I actually want to commit, so this is where we talk about something called a staging area, so inside what we have is a staging area, this is where we are. Temporarily adding or removing files that we want to be in our next commit, so let's say I added that final write and I think I called that test or something, what would I do if I want to add this to my next commit.
I don't commit. yet, but I want to add it and it's a temporary area called staging area while I type get add and then the file name which in this case is readme MD so let's do that and we'll see that nothing goes wrong, everything happens fine and Now, if we want verify what we just did, we wrote git status. Now you can see that it says we are on the master branch, which is by default just our main branch. We don't need to do that or anything. He says no. it commits still and it says changes to be committed it says we created a new readme file called MD so that's because I added this readme file to the staging area I wrote get status to see what was happening in the staging area, OK?
I had a little error there, but anyway, now we have this file inside the staging area, so we added it and now what this means is that it's ready to be committed, so I can go ahead and add more files here in the staging area and when I'm ready, when I've made the changes I want, I can go ahead and commit now. You usually commit once you've made some kind of progress, once you have something that's working or maybe. you're like in the middle of something and you want to store it at that point, that's when you do a commit, you're not really doing it every 5 to 10 minutes, you can do it every few files you change or every time you like. you know, the kind of milestone you reach when you're programming if you want to put it that way, but anyway, once we've got it ready, what you can do is type git commit - M, which means message and then, in quotes , you put what it is. known as a commit message, now the commit message is less than fifty characters and it describes precisely what changed in this commit, so in this case what I did was add the readme file dot MD, that's what I did in this confirmation.
I made it a new I made a new file to build myself so I'll type git commit - M added the readme file MD now look what happens it says master root commit this is actually the commit ID it says Rini thought the file md1 changed an insert and build mode something read me MD, now we just committed that file and made a change. If I actually type git status to see our staging area, we see in the master branch that there is nothing to commit. The working tree is clean and that's as easy as it gets. make a change to a git repository, add your files, make a commit and voila, you've already cached it and saved that commit.
Now what we can do is look for other ways to add files and make commits. so let me go here now and once make a change to this file so let me add another one that says hello let me save that file it's important that I save it and let's come back here and now let's type git status and now when I type git status and we can see the changes not prepared for commit, so this tells me what I did, the changes I made that haven't been prepared yet and that I haven't added and it says, "Okay, we modified the MD readme file" and then it says which is okay, use git add file to update what will be committed, use git checkout to discard the changes to the working directory, so we don't want to do that, what we really want to do is add this file, we want to prepare it and we want to do another commit so what I can do is type git add in the name of that file or what I can do is type git add period and what this means is add all the files so add everything I have. in the repository, that's what it means, just add it to the commit, so when you do a dot, that means literally just add everything, so I'm going to add a dot that will automatically add this file.
Now I can type git status and I can see. which says boom, this is green, we've put these changes ready to be committed and now we can go ahead and make another commit, so commit - a.m. and we'll say sorry, no, since she's going to make changes, you know? This isn't very descriptive, usually you want to be more descriptive, but that's okay, we'll just say changes made and now boom, we have our new commit, changes made, one file change, three inserts, one delete, next thing I'll show you is incredible. They are branches, so let's say right now what I want to do is create a new branch and I want to start working on something and not modify my master branch.
Keep in mindthat this is all happening locally so I have my master branch of code let's imagine this is for one user just for us because this is a local repository and I really don't want to mess up the master branch. I don't want to make any changes there. I want to make them in another branch and then maybe later I'll merge them into the master branch. What I can do is create a new branch so I can say git checkout - B I think it's actually the command and then the name of the new branch that I actually want to check out, so git checkout is the way you switch between branches when you do.
B I think that means creating a new branch and now you can name your branch, so what am I going to do? Here you just have to call this new branch to pay. Beet knew that what I did now was switch to a new new branch, so now what I did was exit my master branch and I branched, so I have copied everything in my master branch to this new branch and now any changes that do in my new branch won't happen in the master branch so let's actually split these screens and look at this so let's go here and say MD Readme internal from new branch and now in our new branch let's do a new commit so let's say get a period, let's add those changes, let's say git commit - M and let's make this first commit on the new branch boom, let's make that commit and now let's go back to the master branch and see if the master branch changed because remember I just made these changes on the new branch, so to change branches what you do is type git checkout and then the name of the branch, so if I want to go to the master branch I type master since I'm already on the new branch, I can't change it, but let's do this , get checkout master and now look at this.
Did you see the file? It automatically removed that change because it had been made on the other branch, so now we have two branches, one branch that is the head of the master branch because it has new changes and the master branch that has our original correct changes. so let's add a new file here, let's do this test dot py and say like imports hello game or something, okay, now let's do a commit, so let's go get Ad dot, so let's add all these files, let's type git status. let's make our new file stop, hello, let's do git commit - M added the PI boom test point inserted, that's awesome, now let's switch to our new branch, so let's say git checkouts new now I'm on this new branch and give us a Second, you will notice it. that inside this folder, so let's get rid of that, we have the change that we made earlier in that branch and we don't have the new file that was in the master branch, so let's say what I really want to do is what I want to update this branch with what's in the master branch, then a change occurred in the master branch, which is a new file, and I really want to get that change and bring it to my new branch, how can I go ahead and do it right?
When we work in this type of system, what I can do is merge the master branch with my branch so I can type git merge and then type master and what this will do is take all the changes from the master branch and merge them with my branch, like this let's do this git merge master merge done using the recursive strategy and now look, we're on our new branch here and we have this test file, we have our readme file that still has this change here and now It looks pretty similar to the master branch except we have this line of code.
Now let's change the branches again, let's say git checkout master and notice, you'll see that this new branch on line five here will disappear and there you have it, it's gone, so you have these two files now, but that line is gone, this is the power of git and this is how the two branches work. Check, create a new one with - be in the git checkout command and then you can commit. change and you can merge these things now that hopefully you have a basic understanding of some git commands, let's look at how to set up a remote repository and get all of this working now in the cloud instead of just on our local machine, so What I'm going to do is go to github and I'm going to create a new repository, so you need to create an account by logging into github.
I'm going to assume you guys can figure it out now. I'm going to go to the plus sign and I'm going to click new repository, so let's do this and what I'm trying to set up here is a remote repository, something that other people can see that is not local to my machine. I'm going to call this repository test. I'm going to call this test underscore because the test has already been performed. I'm going to make this a public repository. I'm not going to give any description and I'm not going to initialize this with a readme file, you can do that if you want, but for this step.
I would recommend that you don't do that because I'm going to show you how we can link our local repository to this remote repository and push what we currently have, so let's go ahead and click on create new repository, let's give it a try here and here. It says quick setup if you've done this kind of thing before, we haven't, so what we're actually going to do is follow the commands that are here, essentially what this says is that we create a new repository but we've done it. We haven't initialized it yet, so we haven't configured anything.
What we need to do is deploy some changes to this repository first to get it configured remotely, so what it says to do here is essentially what we've already done, it says create a new repository on our machine, add a new file, do a commit and then we need to follow these two steps, so what I'm going to do is copy this line of code that you guys will need to copy. this too, so git remote add origin and then this line here, so make sure you copy this and at least make sure you have this URL in your remote repository because you're going to need it, so let's go to our command line now. put this aside and let's type that line by just right clicking so if you copy something and you're in the terminal you can right click on your mouse and it should paste it and then go ahead and press enter which has this.
Just done is adding what's known as a remote, now a remote is essentially a URL to another repository, so what we've done is say, hey, I want to add this remote repository as a kind of link like something we know here . in our local repository so that we can push changes and pull changes, that's what we have done when we say git remote add origin. I said I'm adding a new remote called origin which has this URL so now when we use the word origin we will reference this URL that's all we are doing we are literally assigning the word origin to this URL when we type git remote app, you can add as many remote controls as you want, some people commonly call it that. also as upstream so you can have an Origin which is normally your remote repository because you can work on more than one remote repository and then maybe the company remote repository will be your upstream repository or something like that anyway, so we have that, let me just clear the screen here and now.
I'm going to show you how we push changes to this repository to show us here the command is get push - you origin master, so the first thing I want to do is make sure I'm on the right branch, so I want to check. Normally you wouldn't have any more branches before doing this, but I want to check on the master branch, so check master. We are already on the master branch, but it is important. We are there and then what we are going to write is git push - you look in master what this says is that we push all our commits to the remote source repository and push them to the master branch so we choose where and which branch we want to push to these two because we can also push to another branch, which I'll show you in a second.
You say save these settings. What that means is that the next time we do this, all we have to type is git push. and it will automatically remember that it was Origin and Master that we pushed you, so let's press Enter and see what happens here. Objects listed counting objects and boom, here we go. Branch Master configured on track. Remote Branch Master from Origin, so now I go. go ahead and update this here let's take a look and it says readme dot MD test above and you can see we looked at a readme file and we have these changes now on github so if you had any issues pushing there you probably know why I think I addressed this at the beginning of the video, but I forgot, so I'll bring up here what we need to do before we can work with the remote repository and the reason it worked for me is because I already did it.
This is setting up a username and email, so don't worry if that boost didn't work, just follow what I'm about to show you. This may not work either. This gets a little complicated because you need to authenticate yourself. yourself locally on your machine before you can push and pull from any remote repository, so what I'm going to do here is start by saying git config -- global user dot name and let me do this in full screen so you can guys They can't see it and what I'm going to do is put quotes around the name that I want to be represented by in this remote repository, so in your local repository it doesn't matter, but in the remote repository other people will see it. this potentially, so you want to have some name that identifies you, so I'm going to put Tim as my username, so there we go.
I've set my name global, so now this is stored on github locally and every time I make a switch to a remote repository, I push or pull or whatever. I will be identified by the name Tim. Now the next thing I want to do is use email, so I want to say git config -- global user dot email and here I'm going to put the email that I use on github now, hopefully this should authenticate you. You may not have to use it. Maybe I have to do it. It may ask you to log in to github.
There are a lot of different things that could happen here. To be honest, I don't remember how to authenticate locally to be able to push, so you may have to look up how to do that. There's something called a personal access token that you can also use if you're at least on Windows, but anyway, let's enter our email so I'll put a random email because I'm already authenticated so that's fine and I'll put Tim on gmail .com. In fact, I'm not going to save it because I have another email that I don't want to share with you, but anyway just enter your email and hit Enter and once you've done that, you'll have set your name and email in git, like this which now you can try pressing again and see if it works. you can ask it for your password for github, you can ask it to log in if that doesn't happen, unfortunately you will probably have to go to the internet and figure out how to authenticate, but let's say you are now authenticated and were able to push to this remote repository, if you were able to do that, what we need to do is move on to the next step, which is to understand how to pull data from the remote repository, so I'm in my repository now that I've pushed my changes. and I'm actually going to make a change in this remote repository, so let's go here and let me go to the edit button and I'll just make a change that will hopefully simulate what someone else might change in a remote repository. let's move it so that the readme file only has hello now and you can see that I can commit my changes directly from github.
I'm just going to say updated changes from the readme, so I've committed it now, let's test again and Let's see that we've made a change and that just happened. Now let's go back to our command line and now let's figure out how we can get this change from the remote repository. The way to do this is to use what is known as extraction. so I'm going to say git pull origin master what I'm saying is what I want to pull, so what do I want to do, where do I want to pull from and what branch do I want to take, in this case I want to pull from Origin, which is the remote that we set up and I want to pull the master branch so we go and hit enter and it says mm and boom go ahead and we have those changes so that happened everything worked and now if I go back to my sub.
In the text of the line you can see that Hello is the most recent change because that's what we modified now, let's do this, let's make a change here. I'll add Hello and actually go to this repository here and make a change here as well. I'm going to put hello and I'm going to delete. In fact, let's see here. I'm going to add hello. I'm going to add hello again on line four. I'm trying to find a way to be able to do it. create this conflict so let's do it right so I'll commit this change here in this repository and now what I'll do is add my change here so I'll say add because I made a change I say get commit - M change and now what I want to do is to pull from this remote repository, actually what I want to do is push to this remote repository, so I made some changes here.
I want to push them to this repository, but note and wow, let's come back here. I made a change to this remote repository that I currently don't have on my local machine,so I change this just to be tall and I don't have it on this local machine. Look what happens when I try to push this to the remote repository, so press and you'll see it says some references couldn't be pushed too and then the source updates were rejected because the remote contains work that you don't have, so what need? do and what this tells me is that there are changes in the remote repository that you don't have yet, you need to delete them before it will allow you to upload your changes, that's what it says, so if you get a message like this, what you should do is just get pull first, so I'm going to say git pull origin master and now look at what it said and it said ok boom, let's go ahead and remove all these changes now. see what it says here auto merge failed fixes conflicts and then commits the result so what this tells me is that we removed some changes but when we did we had a conflict in the readme file dot MD the reason why that we had a conflict is because we changed two of the same lines and git doesn't know what to keep, so in this remote repository I change the same line that I changed in this repository and on this local machine right now, if we actually go ahead and look here , I can see this is showing me that there is a merge conflict so when you go ahead and do a like you try to download it and there is a merge so we can't automatically sorry there is a conflict can't automatically merge the code , what you need to do is manually tell git what this code should look like, so what this shows you is that there was a merge and there is a merge conflict, you need to fix this, so what you need to do is remove all these arrows , remove all this stuff and just make this file look like you actually want it to look, so I'm going to change it to look like this. save it and I'm going to resolve this merge conflict.
You can't merge it automatically so I need to manually go in and make the corrections that I made and now what I'm going to do is I'm going to go ahead and actually commit. this change, so git commit - M change is fine, so I realize that what I forgot to do is just add the new change that I wanted to make, so what happens is that when you have a merge conflict, what you should do is fix it. the file so resolve the conflict you need to add those changes and then you need to commit those changes and then you should be fine so we'll say gits ah dots we'll say get commit - em change boom we made the change. that's known as our merge commit, so we committed the merge conflict which we fixed and now I can go ahead and say "get push", so if I do this now, you can see that I'm totally fine to push to the remote repository because I pulled Got the latest changes, fixed the merge conflict and then went back to the remote repository and made the change I wanted to make, that's what happens and in fact it happens quite often: a merge conflict occurs and with luckily you have some kind of software tool, in this case I have a subline text that was able to help me a little to fix it, but all you have to do is go into the file that had the conflict, sometimes there will be multiple files that fix the conflict. conflict. add that file back by committing the change and then you can push and extract again and everything should be up and running now.
The last thing I'm going to show you is pressing another branch and after that I think we've pretty much covered everything. we have to do it. I'm going to say git checkout and we're going to go to the new branch and now what I'm going to do is push this branch to the remote repository, so I'm literally going to say git push. and now I'm going to say origin for where I want to push it and new, so I need to specify that I want to push this here as the new branch to the new remote repository, so I'm going to go ahead and do that. and now we're going to push this branch to the remote repository, so if we get here, you can see it says, Hey, you've pushed a new branch called new and it says, do you want to compare and make a pull request?
Why are you saying that? it's because it knows that what we commonly use branches for is to merge them into the master branch once they're done and once they're good, so let me update this here, you'll see it says two branches, if I click, we can see the new . branch updated 17 minutes ago and let's click on it and go to a new pull request. Now it says it can't be merged automatically because there are conflicting changes. Well, let me go here and make this a girafft pull request, so I'll submit it here. Do this just to show you something and I'm going to go to change files and you can see what it shows me here, this is what I added and this is what I removed from the previous file, this is how it works and this is nice.
The basis for merging things into master is to do what's known as a pull request by having a new branch and then compare it to the master branch and merge them together, kind of squashing them, so with that I think I've covered quite a bit. Everything I can about github basics. I apologize if this video is a little confusing. I'm doing my best here to explain everything. Sometimes it's hard to remember the point where I've never used github before because I've been using it. for a long time, but I hope I've at least given you a good enough introduction that you understand what's happening on github now, maybe you need to look up some of the commands again, but now you have a good foundation that you understand what commitment is what push is what pull is what merge conflict is how to create new branches all the things I cover so anyway if you liked this video leave a like subscribe to the channel and of course I'll watch it. you in another youtube video

If you have any copyright issue, please Contact