Coding

Git Tutorial for Beginners – Crash Course

  • 00:00:01 welcome to the skid basics video git is
  • 00:00:05 a version control system a tool which
  • 00:00:08 allows us to manage our source code
  • 00:00:10 history and it's used by the majority of
  • 00:00:13 programmers nowadays there for at least
  • 00:00:16 understanding the basics is probably not
  • 00:00:19 the worst idea now let's have a look at
  • 00:00:21 these basics in this video
  • 00:00:26 before we dive into get let's quickly
  • 00:00:29 have a look at get and get hop because
  • 00:00:32 if you're just getting started with kid
  • 00:00:34 you might think that both are well kind
  • 00:00:37 of the same in the end and turns out
  • 00:00:39 they are not because get which can be
  • 00:00:42 downloaded right here at git – SCM comm
  • 00:00:45 is a version control system which allows
  • 00:00:48 you to manage your source code history
  • 00:00:50 who have a closer look at that in this
  • 00:00:52 video the important thing is that as I
  • 00:00:55 said you can download get so it's a
  • 00:00:57 local tool a tool you install on your
  • 00:01:01 machine on the other hand we have get
  • 00:01:03 hub you can access github right here on
  • 00:01:06 github.com and github is a hosting and
  • 00:01:09 collaboration provider which has the
  • 00:01:12 purpose to host your git repositories
  • 00:01:15 more about repositories in a few seconds
  • 00:01:17 well and as it's a hosting provider it's
  • 00:01:20 a web-based solution now what does this
  • 00:01:23 mean in the end well you can and that's
  • 00:01:26 purely optional you can push your git
  • 00:01:29 repositories to github so to host your
  • 00:01:32 repositories your code right there
  • 00:01:34 which also allows other people your
  • 00:01:36 colleagues for example to access your
  • 00:01:39 code and to collaborate in projects but
  • 00:01:41 pushing the project from get to github
  • 00:01:44 is totally optional you can work locally
  • 00:01:48 with git because git is the actual
  • 00:01:51 version control system github is just
  • 00:01:54 the hosting provider there are also
  • 00:01:56 alternatives to github
  • 00:01:58 AWS code commit for example so you're
  • 00:02:01 not limited to that
  • 00:02:02 but github is actually the hosting
  • 00:02:05 provider for our projects for the coding
  • 00:02:08 projects that most programmers are using
  • 00:02:10 nowadays so that's it about github for
  • 00:02:13 the moment just keep in mind these are
  • 00:02:15 two different things
  • 00:02:16 although the naming seems to be quite
  • 00:02:18 similar so what about git now well we
  • 00:02:22 already saw that we have this
  • 00:02:24 repositories word right there on the
  • 00:02:26 previous slide and we also will see that
  • 00:02:28 we have branches and commits these are
  • 00:02:31 free keywords we have to understand
  • 00:02:33 before we dive into get now a repository
  • 00:02:36 simply is the location where your code
  • 00:02:39 history
  • 00:02:39 is stored you will see in a few seconds
  • 00:02:41 that we have to tell get that it should
  • 00:02:43 manage certain projects or a specific
  • 00:02:46 project and for that we have to add the
  • 00:02:49 project files to our repository inside
  • 00:02:52 such a repository the codes of course
  • 00:02:54 also structured in an efficient or
  • 00:02:57 logical way because inside the
  • 00:02:59 repository we have a so called branch
  • 00:03:02 the branch is basically the folder have
  • 00:03:06 a look at the go – marks because
  • 00:03:07 actually it's not a folder but I think
  • 00:03:09 it's easier to remember it like that so
  • 00:03:11 we have this folder within that
  • 00:03:13 repository which contains our commits
  • 00:03:16 and this brings us to the last important
  • 00:03:19 words a commit simply stands for the
  • 00:03:21 different stages the different versions
  • 00:03:23 of our source code that we save inside a
  • 00:03:27 branch so in the end we are able to save
  • 00:03:30 our code so let's say we have the
  • 00:03:31 starting code and the finish code so two
  • 00:03:33 versions of the code in two commits
  • 00:03:35 these two commits are saved inside a so
  • 00:03:39 called branch and this branch is part of
  • 00:03:42 the git repository and this probably
  • 00:03:45 sounds a little bit abstract right now
  • 00:03:47 so let's dive into gate now and see how
  • 00:03:50 this works in practice to work with kid
  • 00:03:53 we have to download it so just go to
  • 00:03:55 gate – SCM comm and click right here to
  • 00:03:59 download the latest get version for your
  • 00:04:01 operating system the installation is
  • 00:04:03 quite straightforward actually so you
  • 00:04:05 shouldn't have any problems with that
  • 00:04:06 and after you install kit well there is
  • 00:04:11 not a lot that you will see because git
  • 00:04:13 is not coming with some kind of
  • 00:04:15 interface you basically run git with the
  • 00:04:18 terminal or the command prompt on
  • 00:04:20 Windows you can use the default system
  • 00:04:24 terminal or you can use an integrated
  • 00:04:26 terminal in your code editor
  • 00:04:28 which is what I will do right here I
  • 00:04:29 will use Visual Studio code and right
  • 00:04:32 here if you click on to view and
  • 00:04:33 integrate the terminal you can find this
  • 00:04:36 terminal right here so I will use this
  • 00:04:38 one but feel free to use any kind of
  • 00:04:40 terminal and any kind of code editor of
  • 00:04:42 your choice and with our terminal
  • 00:04:44 commands we can then control get we also
  • 00:04:48 have code editors also like wishes to
  • 00:04:50 the code which come with some integrated
  • 00:04:52 gate function
  • 00:04:53 right here the source coal tap but this
  • 00:04:56 is not something we'll have a look at in
  • 00:04:57 this video so what we can do now is we
  • 00:05:00 can simply create a new project by going
  • 00:05:02 to open folder right here in my case and
  • 00:05:04 let's maybe call it project like that
  • 00:05:06 and open it
  • 00:05:08 that's quite straightforward actually we
  • 00:05:11 could create a new file let's say
  • 00:05:13 index.html and we could say we want to
  • 00:05:15 have a paragraph with hello something
  • 00:05:18 like this now what we could do now is we
  • 00:05:21 could save this project and with that we
  • 00:05:24 would have the index.html file right
  • 00:05:26 here in our project folder and it would
  • 00:05:29 be saved but what if we would add a
  • 00:05:32 second paragraph maybe some text right
  • 00:05:36 here now we could also save this one and
  • 00:05:39 we would have saved it right there also
  • 00:05:41 no problem but if you want to go back to
  • 00:05:43 our previous stage of the code then we
  • 00:05:46 could use ctrl Z or command Z right here
  • 00:05:49 on the Mac but after we closed our
  • 00:05:51 editor and reopen it this option would
  • 00:05:53 not be available and the previous
  • 00:05:55 version of our code would be gone of
  • 00:05:57 course you could also say we create a
  • 00:06:00 new folder for each instance of our code
  • 00:06:03 but to be honest in practice you would
  • 00:06:05 never do that and this is forged comes
  • 00:06:08 into play over version management in
  • 00:06:10 general comes into play because this
  • 00:06:12 allows us to manage our different
  • 00:06:14 versions our source code history in a
  • 00:06:17 very efficient and easy to maintain
  • 00:06:19 way and one tool for version management
  • 00:06:23 is git of course therefore let's see how
  • 00:06:26 we can turn our project into a project
  • 00:06:28 managed by git and as I said we have to
  • 00:06:31 use the terminal for that so let me open
  • 00:06:33 the integrated terminal right here and
  • 00:06:35 you have to navigate to your project
  • 00:06:38 folder this is done automatically right
  • 00:06:39 here by Visual Studio code and now we
  • 00:06:42 simply type git init this will simply
  • 00:06:45 initialize a git repository we talked
  • 00:06:48 about that on the slide and basically
  • 00:06:50 tell git hey please manage the project
  • 00:06:54 in this folder so if we press ENTER now
  • 00:06:56 we can see that we initialized an empty
  • 00:06:59 git repository but that's interesting
  • 00:07:01 and empty though we'll have a look at
  • 00:07:03 that in a few seconds but if we go back
  • 00:07:05 now to our folder
  • 00:07:07 we can see make sure to unhide the
  • 00:07:09 hidden files in case this folder is not
  • 00:07:11 visible in your case so we can see that
  • 00:07:14 get now edit this folder right here and
  • 00:07:17 this simply contains all the files it
  • 00:07:19 needs to create that repository and with
  • 00:07:23 that we now make sure that git will
  • 00:07:25 monitor and control all the files inside
  • 00:07:28 this folder nevertheless we saw that get
  • 00:07:32 says the repository is empty at the
  • 00:07:35 moment and if we enter get status' right
  • 00:07:38 here we can also see why this is the
  • 00:07:41 case because we have untracked files
  • 00:07:44 right there so this means get knows that
  • 00:07:47 we have some files in this folder it
  • 00:07:49 kind of controls this folder so it is
  • 00:07:51 aware of that fact but we have to
  • 00:07:53 explicitly tell git which files it
  • 00:07:56 should include in our repository and
  • 00:07:58 therefore which code parts it should
  • 00:08:01 track so what we have to do right now to
  • 00:08:03 tell git well please track these files
  • 00:08:05 we simply type git add space dot this
  • 00:08:10 will simply add all the files of your
  • 00:08:13 project folder to the tracking logic of
  • 00:08:15 git so if we press ENTER now and type
  • 00:08:20 git statue's once again we can see that
  • 00:08:23 we now have this green color which
  • 00:08:26 indicates that we staged this file this
  • 00:08:29 basically means that git is not aware of
  • 00:08:31 that file and tracked the changes we
  • 00:08:33 apply it so we basically created the
  • 00:08:35 file and edit the content these are the
  • 00:08:37 changes we have right now and if we now
  • 00:08:39 enter git commit – M that's a shortcut
  • 00:08:45 you normally use to do two things
  • 00:08:47 you first tell git that it should commit
  • 00:08:49 these changes so basically add this code
  • 00:08:53 right here as a version of the code that
  • 00:08:56 we kind of want to save in our so called
  • 00:08:58 branch and then we simply have to add
  • 00:09:01 minus m to give that commit a name
  • 00:09:05 because all commits have to be named
  • 00:09:07 because this will allow us later to
  • 00:09:09 easily see what exactly changed in this
  • 00:09:13 commit that we did so we could for
  • 00:09:15 example name this starting code
  • 00:09:17 something like that
  • 00:09:18 if you press ENTER now
  • 00:09:21 we can see that the committee was
  • 00:09:23 created and if we now enter get statues
  • 00:09:26 once again we can see that we have
  • 00:09:28 nothing to commit our so-called working
  • 00:09:30 tree is clean and if we now enter good
  • 00:09:33 branch right here like that we can see
  • 00:09:36 that get automatically created this
  • 00:09:38 so-called master branch right here and
  • 00:09:41 that's the first important thing you
  • 00:09:44 have to keep in mind from a structural
  • 00:09:45 perspective if we think back about the
  • 00:09:48 slide now we know that we created that
  • 00:09:50 repository by typing git init inside
  • 00:09:55 this repository we added a file the
  • 00:09:57 index.html file with some code in it
  • 00:09:59 then we told get with git add dot that
  • 00:10:02 we want to track the changes off this
  • 00:10:04 file so I'm going to stage this file
  • 00:10:06 basically and with git commit we in the
  • 00:10:09 end committed our code and added it to
  • 00:10:12 our repository and with that we
  • 00:10:14 automatically created the master branch
  • 00:10:16 so this commit is now saved inside the
  • 00:10:19 master branch inside our repository in
  • 00:10:22 this folder what you can do now is we
  • 00:10:25 can add some more changes let's let me
  • 00:10:26 say we add a div and say another text
  • 00:10:30 something like that if we save that go
  • 00:10:34 back into our terminal now enter git add
  • 00:10:37 to add the changes right here and then
  • 00:10:40 say git commit minus M once again and
  • 00:10:43 let's say diff add it like that then we
  • 00:10:48 also added this new code right here to
  • 00:10:51 our repository to our branch and that's
  • 00:10:54 important we also saved these two
  • 00:10:56 snapshots so if we enter git log right
  • 00:10:59 now you can see that we have our last
  • 00:11:03 commit this one right here which is now
  • 00:11:05 the so-called head so the latest commit
  • 00:11:07 in our branch and if we go down a bit we
  • 00:11:12 can see that we also have our first
  • 00:11:13 commit these starting code that's the
  • 00:11:16 name that we defined for this commit you
  • 00:11:19 can leave this menu by entering Hugh
  • 00:11:21 right here to exit it now before we
  • 00:11:23 continue one important information again
  • 00:11:25 git does not create copies of each
  • 00:11:29 commit that you create right here get
  • 00:11:32 simply tracks changes we saw
  • 00:11:34 engage statues so basically when we add
  • 00:11:37 git add git has a look at our different
  • 00:11:41 files in the code and sees if we change
  • 00:11:43 something and if we commit that in the
  • 00:11:45 end these changes are saved but git is
  • 00:11:48 not creating copies of the code again
  • 00:11:51 and again and again this would be highly
  • 00:11:53 unofficial and would simply bloat our
  • 00:11:55 entire folder
  • 00:11:56 therefore git is really smart regarding
  • 00:11:58 that and therefore it's a really nice
  • 00:12:00 version control tool to use with that
  • 00:12:03 let's have another look at our commits
  • 00:12:05 right here because if we scroll up to
  • 00:12:08 our last commit so this one right here
  • 00:12:10 which we named div edit then we can see
  • 00:12:13 that head master is written down here
  • 00:12:15 the important thing is that head part
  • 00:12:18 let's have a closer look at that because
  • 00:12:21 if I now let's say add another div
  • 00:12:26 testing the head maybe something like
  • 00:12:29 that
  • 00:12:29 save this add it and finally commit the
  • 00:12:34 change let's say head testing something
  • 00:12:38 like that and we again have a look at
  • 00:12:40 our commits now you can see that now
  • 00:12:43 this last commit I made is the new head
  • 00:12:47 so that's important to keep in mind
  • 00:12:49 whenever you create a new commit this
  • 00:12:51 last commit will be the head in your
  • 00:12:54 branch now why is this important
  • 00:12:56 let's say you want to go back to a
  • 00:12:58 previous commit maybe this one right
  • 00:13:01 here our diff edit commit so for that we
  • 00:13:05 simply copy the idea this is the ID of
  • 00:13:08 this commit and each commit has a unique
  • 00:13:11 idea of course and now I simply say git
  • 00:13:13 checkout right here and now enter the ID
  • 00:13:19 with that we are now back in our code
  • 00:13:23 that we had before but that's important
  • 00:13:25 the head is now also pointing towards
  • 00:13:29 this commit but that's important thing
  • 00:13:32 this commit is no longer part of our
  • 00:13:34 master branch so basically this commit
  • 00:13:37 is kind of in the middle of nowhere now
  • 00:13:40 you can use this feature this check out
  • 00:13:42 feature like that to have a look at some
  • 00:13:44 previous code and to see okay what did i
  • 00:13:46 do right there in case something went
  • 00:13:48 to see how did I approach it previously
  • 00:13:50 but if you would like to go back to this
  • 00:13:53 commit then you cannot just check it out
  • 00:13:55 and add it right here and commit it
  • 00:13:58 because this will basically not work as
  • 00:14:00 this commit is no longer part of the
  • 00:14:02 actual branch but how can you now go
  • 00:14:04 back to this commit in case you don't
  • 00:14:06 want to have the last commit you just
  • 00:14:08 created well for that we first changed
  • 00:14:10 back to our last commit by simply
  • 00:14:12 entering get master in that case because
  • 00:14:15 we are in the master branch and as you
  • 00:14:17 can see right here we are now back in
  • 00:14:19 our last commit we can also check this
  • 00:14:21 with git log and as you can see head
  • 00:14:23 testing now again is the head right here
  • 00:14:26 and down there
  • 00:14:28 if edit is no longer the head but now we
  • 00:14:32 want to get rid of this head testing
  • 00:14:35 commit so for that we simply go to the
  • 00:14:38 commit you want to go back to that's
  • 00:14:40 important don't select this last commit
  • 00:14:43 right here so the one you want to delete
  • 00:14:45 but select the commit that you want to
  • 00:14:47 jump back to so an our case this one
  • 00:14:49 right here the diff edit commit copy
  • 00:14:52 that ID and now add git reset – man is
  • 00:14:57 hard and enter the ID if we now press
  • 00:15:01 ENTER you can see that the head is now
  • 00:15:04 our DIF added commit and if we log it
  • 00:15:08 again let's see what happens we can see
  • 00:15:10 that the diff added commits indeed is
  • 00:15:14 the head we knew that but if we go down
  • 00:15:16 right here with the arrow keys by the
  • 00:15:17 way we can see that we only have these
  • 00:15:20 two commits being displayed in our
  • 00:15:23 well-working tree right here the
  • 00:15:26 important thing is that as we cannot see
  • 00:15:27 the other commit right here we cannot
  • 00:15:29 jump back to it so you have to be
  • 00:15:31 careful when you delete such a commit
  • 00:15:33 but generally it can be done as we saw
  • 00:15:36 it right here so this was the head and
  • 00:15:38 how we can check out all the commits and
  • 00:15:41 then also delete your commits in case we
  • 00:15:44 want to jump back to these previous
  • 00:15:46 commits permanently but as I said be
  • 00:15:48 careful when doing this but what happens
  • 00:15:51 if you let's say have your commit so we
  • 00:15:54 are in this diff edit and now you add
  • 00:15:56 some code something I don't need for
  • 00:16:00 example
  • 00:16:02 like that and now you say mmm I don't
  • 00:16:06 need that code I did something wrong I
  • 00:16:07 spent 10 minutes and actually it doesn't
  • 00:16:10 work I just want to go back to the
  • 00:16:11 commit I initially had so basically to
  • 00:16:14 the statues we have right here now keep
  • 00:16:16 in mind the changes right here we have
  • 00:16:18 were not staged so we didn't add get add
  • 00:16:21 dot and of course we also didn't commit
  • 00:16:24 these changes so basically what you want
  • 00:16:27 to do is we want to revert all unstaged
  • 00:16:30 changes and go back to our last commit
  • 00:16:32 for that we simply go to our terminal
  • 00:16:35 once again and now enter git checkout
  • 00:16:38 that's the same command we used before
  • 00:16:40 when we checked out our commit and now
  • 00:16:43 we add a space – – another space and a
  • 00:16:47 dot if we now press ENTER you can see
  • 00:16:50 that this is not working now because
  • 00:16:51 well I accidentally forgot to save my
  • 00:16:54 progress right here in my code editor so
  • 00:16:55 let's save it now let's now again type
  • 00:16:58 git checkout – – the dot don't forget to
  • 00:17:02 spaces and if you do this now like that
  • 00:17:04 you can see the changes are reverted so
  • 00:17:07 this can be another really helpful
  • 00:17:09 command when getting started with git
  • 00:17:12 now with that we covered all the core
  • 00:17:14 functionalities of the commit area I
  • 00:17:17 would say there is a lot more to dive
  • 00:17:19 into but to get started this is
  • 00:17:21 basically everything you need to play
  • 00:17:23 around with the commits but we also had
  • 00:17:26 these branches you remember if I enter
  • 00:17:28 git branch right here then we see
  • 00:17:31 indicated by the star by the way that we
  • 00:17:33 now are in the master branch which was
  • 00:17:36 automatically created after we added our
  • 00:17:39 first commit after initializing our
  • 00:17:41 repository now a branch basically
  • 00:17:44 contains the code that we have all the
  • 00:17:47 different commits the different versions
  • 00:17:49 of it but if you think about a typical
  • 00:17:51 work for you could have this means you
  • 00:17:52 could work in the master branch in your
  • 00:17:55 core project you build your website and
  • 00:17:57 it might be done but then you say well
  • 00:18:00 the website is running in a stable way
  • 00:18:01 but I want to add a new feature but I
  • 00:18:04 don't want to crash the actual site then
  • 00:18:06 you can also create another branch for a
  • 00:18:08 specific feature then you can keep
  • 00:18:11 working in both branches you can work on
  • 00:18:13 the master branch to add some bug fixes
  • 00:18:15 for it
  • 00:18:16 and at the same time you or another
  • 00:18:18 coder can work on the other branch you
  • 00:18:21 created and implement that special new
  • 00:18:23 feature and after this new feature is
  • 00:18:25 finished you can merge both branches now
  • 00:18:29 again this sounds a little bit
  • 00:18:30 complicated so let's try it out
  • 00:18:32 so let's first create a new branch for
  • 00:18:35 that we add git checkout minus B and now
  • 00:18:40 we have to define a branch name this
  • 00:18:42 could be new feature for example be
  • 00:18:45 careful you have to add these dashes
  • 00:18:47 between the words to make sure the
  • 00:18:49 branch can be created with that we now
  • 00:18:52 switch to a new branch named new feature
  • 00:18:55 and if we have a look at that branches
  • 00:18:58 that we have right now by entering it
  • 00:18:59 branch you can see that we have the
  • 00:19:02 master and the new feature branch and
  • 00:19:04 that we are currently in this new
  • 00:19:06 feature branch important if we have a
  • 00:19:09 look at the commits inside this branch
  • 00:19:11 we can see that this branch includes all
  • 00:19:14 the commits we had in our master branch
  • 00:19:17 we can also see it right here with the
  • 00:19:19 head which is now the last commit if
  • 00:19:21 edit and which is the head for both the
  • 00:19:24 new feature branch and our master branch
  • 00:19:27 right here now let's say in this new
  • 00:19:30 feature branch we now want to add a file
  • 00:19:32 let's maybe Sadie style.css file
  • 00:19:36 something like that and that's actually
  • 00:19:38 all you wanted to do them so let's say
  • 00:19:41 git add down here and get commit – m CSS
  • 00:19:47 added like that if we now have a look at
  • 00:19:51 our log file once again you can see that
  • 00:19:53 for the new feature branch this last
  • 00:19:57 commit right here is now the head but
  • 00:20:00 the master so right here still has our
  • 00:20:04 diff edit commit as the head because of
  • 00:20:07 course we added this new commit only to
  • 00:20:09 our new feature branch right here with
  • 00:20:12 that let's change back to our master now
  • 00:20:14 and to change branches you have two
  • 00:20:17 options
  • 00:20:17 normally you simply enter get check out
  • 00:20:21 another branch name in this case this
  • 00:20:23 would be master but for the master
  • 00:20:26 branch you can also use a shorter way by
  • 00:20:28 simply typing it
  • 00:20:29 master like that so now we're back in
  • 00:20:32 the master branch and as you can see
  • 00:20:34 right here the CSS file is of course not
  • 00:20:38 included so actually we would like to
  • 00:20:40 merged it now to make sure this new
  • 00:20:42 feature the CSS code is added to our
  • 00:20:45 master branch right here to do this we
  • 00:20:47 simply have to be in the master branch
  • 00:20:49 which we are right now and then we
  • 00:20:51 simply type git merge and now enter the
  • 00:20:54 name of the branch that you want to
  • 00:20:56 merge right here in our case this is the
  • 00:20:59 new feature branch this one right here
  • 00:21:01 and if we now press ENTER then you can
  • 00:21:04 see that we now added the change
  • 00:21:07 basically so the addition of the CSS
  • 00:21:09 file to our master branch and if we now
  • 00:21:12 have a look at our log right here then
  • 00:21:15 you can see that this now this new
  • 00:21:18 commit is now the head of both our
  • 00:21:20 master and our new feature branch and
  • 00:21:23 this allowed us to basically add this
  • 00:21:25 new feature in a separate branch and
  • 00:21:27 then merging it back into our master
  • 00:21:30 branch what we can do now is of course
  • 00:21:33 as we don't need our new feature branch
  • 00:21:35 anymore we can get rid of this branch
  • 00:21:37 for that we simply enter git branch
  • 00:21:41 minus D capital D and now the name of
  • 00:21:45 the branch that you want to delete this
  • 00:21:47 should of course not be the branch we
  • 00:21:48 are currently in so in our case this is
  • 00:21:51 the new feature branch right here so
  • 00:21:54 let's press enter and as we can see we
  • 00:21:57 now deleted our new feature branch and
  • 00:21:59 if we enter git branch right now like
  • 00:22:02 that we can see that we only have the
  • 00:22:04 master branch again but now including
  • 00:22:06 our CSS file so this is another basic
  • 00:22:10 way how we can use these branches and
  • 00:22:12 how good things about these branches
  • 00:22:14 there is only one less thing that I
  • 00:22:17 would like to show you because let's
  • 00:22:19 create another branch now we learned how
  • 00:22:22 to works by simply typing git checkout –
  • 00:22:26 beam and let's maybe call it again new
  • 00:22:28 feature like that and in this new branch
  • 00:22:31 we are now in I will change hello in my
  • 00:22:34 index.html file – good bye like that so
  • 00:22:40 again I will save the change and I will
  • 00:22:42 say git add
  • 00:22:43 and get commit – em added good-bye maybe
  • 00:22:50 like that and that's it
  • 00:22:52 we now edit this change in our new
  • 00:22:54 branch now let's switch back to the
  • 00:22:56 master right here and let's also change
  • 00:22:59 exactly the same text right here but
  • 00:23:02 maybe to buy something like that so it's
  • 00:23:05 important we changed the same element
  • 00:23:07 basically so let's stage this change and
  • 00:23:11 of course also commit it like that edit
  • 00:23:15 by like that and now the question is
  • 00:23:19 what happens if I want to merge these
  • 00:23:21 two branches well let's try it out so
  • 00:23:24 we'll add git merge new feature to merge
  • 00:23:27 the master with this new feature branch
  • 00:23:29 and if I now press Enter well then you
  • 00:23:33 can see that get identified a conflict
  • 00:23:36 normally get tries to solve such
  • 00:23:39 conflicts on its own but in that case
  • 00:23:41 well how should it know which version it
  • 00:23:44 should keep my IDE right here or my code
  • 00:23:47 editor helped me already
  • 00:23:49 I can select right here except current
  • 00:23:52 change to accept the change as we did it
  • 00:23:54 in the master branch we can accept the
  • 00:23:57 incoming change that's the change we
  • 00:23:59 have from the new feature branch we can
  • 00:24:02 accept both changes or we can compare
  • 00:24:04 the changes right here so to see it vice
  • 00:24:06 versa now I don't need that actually and
  • 00:24:09 I also don't want to rely on to my code
  • 00:24:12 editor right here because let's say you
  • 00:24:15 don't have this feature in the terminal
  • 00:24:17 for example and you want to keep the
  • 00:24:19 goodbye change down here what you can do
  • 00:24:22 now is you can simply delete all the
  • 00:24:24 code we don't need so this one right
  • 00:24:25 here and right there
  • 00:24:27 and also this new feature line like that
  • 00:24:30 now we save this and now important add
  • 00:24:34 well git add like this and now commit –
  • 00:24:38 M merge resolved maybe something like
  • 00:24:43 that and if you now hit enter you can
  • 00:24:45 see that we now naj the file we have the
  • 00:24:48 goodbye text up here and that's
  • 00:24:51 important we don't have any conflict
  • 00:24:53 anymore and if I lock this now right
  • 00:24:55 here you can see that we have
  • 00:24:57 the merge resolve commit as the last
  • 00:24:59 commit that we have and before we have
  • 00:25:01 to edit by commit right here so that's
  • 00:25:04 it actually
  • 00:25:05 with that we covered the very basics of
  • 00:25:08 get right here so it's important to keep
  • 00:25:11 in mind that concept of repositories
  • 00:25:14 branches and commits and how you can
  • 00:25:17 interact with these how you can create
  • 00:25:19 new branches how you can check out
  • 00:25:21 branches how you can check out commits
  • 00:25:23 and a lot more also keep in mind that
  • 00:25:25 you can delete commits and that you can
  • 00:25:28 also delete branches as we've already
  • 00:25:29 here but if we delete branches or
  • 00:25:32 commits these are basically gone so be
  • 00:25:36 really careful when doing this because
  • 00:25:38 well as I said if it's gone then it's
  • 00:25:41 gone and then it's hard or impossible to
  • 00:25:43 get it back however as I said we only
  • 00:25:46 had a look at the basics now and if you
  • 00:25:49 want to dive deeper how can you continue
  • 00:25:51 well the best resource is this one right
  • 00:25:54 here this is again on git SCM comm a
  • 00:25:57 link can be found in the video
  • 00:25:58 description and this well as the first
  • 00:26:01 sentence already indicates if you can
  • 00:26:04 only read one chapter to get going with
  • 00:26:06 get this is it
  • 00:26:07 and I can highly recommend this second
  • 00:26:09 chapter right here because it dives into
  • 00:26:11 all the basics we had a look at right
  • 00:26:13 now
  • 00:26:14 and even though I've deeper in some
  • 00:26:16 areas to make sure you can practice what
  • 00:26:18 we learned so far even more and also
  • 00:26:20 dive deeper if you want you another way
  • 00:26:24 to get started with get quicker is to
  • 00:26:27 kind of try to memorize the core
  • 00:26:29 commands we use right here throughout
  • 00:26:31 this video I summarized these right here
  • 00:26:34 on the slide let's maybe have a look at
  • 00:26:36 these quickly for the initialization we
  • 00:26:39 have to navigate through a project
  • 00:26:41 folder of course and then type git init
  • 00:26:43 to initialize the repository and we can
  • 00:26:46 use git statues all the time to well see
  • 00:26:49 the status of our git repository if we
  • 00:26:51 have any untracked changes for example
  • 00:26:53 now regarding the commits we can use git
  • 00:26:56 add to stage our changes and if we add
  • 00:26:59 the dot this will basically stage all
  • 00:27:01 the files we have in our project right
  • 00:27:04 here in our branch then we have git
  • 00:27:07 commit – M and then we have to define a
  • 00:27:09 name for the commit sub if that you will
  • 00:27:11 create a new commit right here we also
  • 00:27:14 have good lock which allows us to get an
  • 00:27:16 overview of all our commits that we have
  • 00:27:18 in the branch we are currently located
  • 00:27:20 in we also have to get checkout which
  • 00:27:23 you can use to do both
  • 00:27:24 check out branches or in that case
  • 00:27:26 commits keep in mind that you can use
  • 00:27:28 git log to get the ID of a specific
  • 00:27:30 commit and then get checkout plus ID to
  • 00:27:33 check out this commit then we have git
  • 00:27:35 checkout space – – space start this
  • 00:27:39 simply helps us to go back to the last
  • 00:27:41 commit we did and to get rid of all
  • 00:27:44 unstaged changes and be careful right
  • 00:27:47 here we have get reset – – hard and then
  • 00:27:50 the ID of the community want to go back
  • 00:27:53 – but if you do that all the later
  • 00:27:56 commits so all the commits after the
  • 00:27:58 commit to 50 ID we start right here will
  • 00:28:01 not be part of our working tree anymore
  • 00:28:03 so be careful when using this one we
  • 00:28:06 also have branches and commands for the
  • 00:28:08 branches the first one is of course get
  • 00:28:11 branch it gives us an overview of all
  • 00:28:13 the branches that we have in our
  • 00:28:15 repository we also have kid check out as
  • 00:28:18 we headed for the commit we talked about
  • 00:28:20 that already then we have kid check out
  • 00:28:23 – B and then a name this simply helps us
  • 00:28:26 to create a new branch based on the
  • 00:28:29 current branch we sorted all the commits
  • 00:28:31 of the branch we're currently in will
  • 00:28:33 also be part of that newly created
  • 00:28:35 branch we also have git merge we saw
  • 00:28:38 that we can use it if we have some
  • 00:28:40 specific projects for example some side
  • 00:28:43 functionalities that you want to test
  • 00:28:44 and implement and finally merge our
  • 00:28:47 additional branch with this new feature
  • 00:28:49 with our master branch but be careful we
  • 00:28:52 saw we can also have conflicts right
  • 00:28:54 here we also saw how we can solve these
  • 00:28:55 and then we have git branch minus D plus
  • 00:28:59 the branch name this is also a command
  • 00:29:02 we can use but we have to be careful
  • 00:29:05 because well when we use this the branch
  • 00:29:07 we define right here will be deleted and
  • 00:29:10 that's it actually what I can recommend
  • 00:29:13 now if you just get started with geared
  • 00:29:14 play around with it create your projects
  • 00:29:17 save different commits change branches
  • 00:29:20 create branches try to Smerch feature
  • 00:29:22 and a lot more and dive deeper in
  • 00:29:25 the official documentation that we just
  • 00:29:27 talked about a few seconds ago with that
  • 00:29:29 I can only say thanks a lot for watching
  • 00:29:31 hope to see you in the next videos and
  • 00:29:33 bye