Git and GitHub Tutorial for Beginners

Kevin Stratvert
24 Jun 202246:18

Summary

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.
The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Q & A

  • What is Git and why would someone use it?

    -Git is an open source version control system that allows you to manage changes to your files over time. It lets you track changes, go back to previous versions, compare differences, see who made changes, and more. It's useful for source code management, tracking content changes on sites, collaborating on projects, and overall keeping a history of changes.

  • How do you get Git setup on your computer?

    -You need to first install Git by downloading it from the Git website or through a package manager. Once it's installed, you can interact with Git through the command line interface or GUI tools. You'll also want to configure your name and email to associate commits with.

  • What does it mean to commit changes in Git?

    -Committing in Git creates a snapshot of your repository at that point in time. It captures what all your files look like at that moment and adds an entry to the project history. Commits allow you to go back to previous versions of your code or content.

  • How can you collaborate with others using Git?

    -You can collaborate by using a hosted Git platform like GitHub. This gives you a centralized, cloud-based repository that your team can share. Members can fork repositories, create branches to work on features, then submit pull requests to merge their code. Issues and comments also facilitate collaboration.

  • What happens when you try to merge branches with conflicting changes?

    -When the same part of a file was edited on two different branches that are being merged, it creates a merge conflict. Git cannot automatically reconcile the conflicting changes. The conflicts must be manually resolved by editing the file to select which code to preserve before merging can happen.

  • How can you undo changes or go back to older versions of your files?

    -Git stores the entire history of a project, so you can use commands like git reset and git checkout to revert back to an older commit. This rolls back your code to look like it did at an earlier point. You can retrieve old versions without having to redo work.

  • What is a Git branch and why would you use branching?

    -A branch is essentially a copy of your main codebase that lets you develop features or test out changes without impacting the main/production version. Branching is useful for trying new ideas, fixing bugs, working on team tasks in parallel, or stabilizing production code while developing.

  • What is GitHub and how does it work with Git?

    -GitHub is a web-based platform for hosting and collaborating on Git repositories in the cloud. You push your local Git repo up to GitHub to create a centralized place for your team to access the project, track issues, review code, merge branches via pull requests, and more.

  • If I delete a tracked file locally, can I recover it with Git?

    -Yes, if you have previously committed a file in Git and then delete it locally, you can use the git restore command to recover the deleted file from the most recent commit. Git's version history keeps snapshots of all commits, enabling file recovery.

  • How can I ignore files like logs and temporary files from getting tracked in Git?

    -You can create a .gitignore file to specify intentionally untracked files that Git should ignore. Common examples are files containing sensitive data, system-generated files, compilation artifacts, and temporary files that can be reproduced.

Outlines

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Mindmap

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Keywords

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Highlights

The video is abnormal, and we are working hard to fix it.
Please replace the link and try again.

Transcripts

play00:00

Hi everyone, Kevin here.

play00:01

Today we are going to learn how  to use both Git and also GitHub.

play00:07

We'll start with what even is  Git and why would you use it.

play00:12

Then we'll look at how you can  get Git running on your computer,  

play00:15

and then we'll look at how you can use it.

play00:18

After that, we'll look at GitHub.

play00:21

GitHub is a hosting platform where you can  collaborate with others on your Git repositories.

play00:27

By the end of this video, you'll be  proficient in using both Git and also GitHub.

play00:33

If you'd like to follow along, I've included  some sample files down below in the description.

play00:38

All right, let's check this out.

play00:41

First off, what even is Git?

play00:44

Git is open source and free source control  management or what's referred to as SCM.

play00:53

With Git, you can manage  changes to files over time,  

play00:57

and you can go back and see  what those changes were.

play01:00

Here for example on the  KevinCookieCompany.com website,  

play01:04

I say that our eggs come from chickens  that listen to classical music.

play01:12

Did anyone ever really believe that? We  don't play classical music for our chickens.

play01:17

So, I need to update this text on the website.

play01:20

I can now create another version  of this website or another branch  

play01:26

and then I can update the text there. Once  I'm confident that the changes look good,  

play01:31

I can then merge that back into the  main branch and then I can commit that.

play01:36

Basically, that means that my changes  will now show up on the website.

play01:41

Now, let's say that maybe the operations  manager comes up to me and says, hey Kevin,  

play01:46

we actually do play classical  music to all of our chickens.

play01:50

Well, with Git, I can simply  revert back to a previous version.

play01:54

That's the magic of using Git.

play01:56

I could revert back to previous versions.

play01:59

I can compare the differences between  different versions. I can see who changed what.

play02:05

Basically, if I screw something up, well, I  could just jump back to a previous version.  

play02:11

Now that we know what Git is, next, we need  to install it on our computer and to do that  

play02:17

you can head to the website up above or you can  click on the link down below in the description.

play02:23

Once you land on the website, click on downloads  

play02:26

and then select your operating system and  then run through the installation process.

play02:31

When I installed Git, it came  with a terminal called Git Bash.

play02:36

To launch it, simply click on your Start menu and  then type in Git Bash and then you can launch it,  

play02:42

but you could also use any other  terminal that you have on your computer.  

play02:46

You could also use PowerShell or command  prompt. If you're on Mac, you could use  

play02:51

the terminal that comes with your machine. You  could also download third party terminals like  

play02:56

Hyper.is and that works across all different  platforms, so the choice is really yours.

play03:02

Once you've installed Git, you can use any  terminal now to interact with Git. For this video,  

play03:08

I'm going to use Git Bash simply because it  came with the Git installation on Windows.

play03:13

Here I am in File Explorer, and I have these four  

play03:17

different files that make up the  KevinCookieCompany.com website.

play03:21

If you would like to follow along,  

play03:23

you can download all of these files  in the description of this video.

play03:27

I want to use Git for source control.

play03:30

So how do we do that?

play03:31

Well, let's open up Git Bash.

play03:33

This is the terminal that we just installed.

play03:35

Now again, you could also use any  other terminal that you would like.

play03:39

Here I am in Git Bash and before we can get  started, we have to configure a few things.

play03:45

First, we need to specify your  name and also your e-mail address.

play03:51

The reason this is so important  is any time we commit something or  

play03:54

write something to the history book,  we need to know, well, who's doing it.

play03:58

First, let's specify the name.  Here type in git config --global  

play04:04

user.name, then insert quotes and  here you can type in your name.

play04:09

I'll type in Kevin Stratvert and then  close my quotes and then I'll press enter.

play04:15

Next, we also need to specify your e-mail  address. In here let's type in git config  

play04:21

--global user.email and then  type in your e-mail address.

play04:25

I'll type in [email protected]  and then hit enter. Next, we also need to set  

play04:32

the default branch name and that might  not make that much sense right now.  

play04:36

Later on, we'll talk more about what branches  are and why you might want to use them.

play04:41

But for now, let's once again  type in git config --global  

play04:45

init or initialize.default branch and we're  going to call the default branch main.  

play04:52

Once you type all of that in,  let's once again press enter.

play04:55

So far, we've been using a  command called git config,  

play04:59

and as we're going through this, if there's  ever a command and you're not quite sure  

play05:02

what it does or what different  options you have for that command,  

play05:06

you can very easily ask git for help. Here for  example, I could type in git config and then I can  

play05:11

type in a - with an h. When I press enter, this  will show me help information about git config.

play05:17

Now zoom out a little bit more  

play05:19

and here you can see all the different  ways that you can configure things.

play05:23

Down below as well if you want  more detailed help information,  

play05:26

you could also type in git help  and then the command config.

play05:31

Here I'll press enter.

play05:32

This opens up a manual that's hosted on your  computer, so even if you're on the go or you  

play05:37

don't have Internet access, you'll still be able  to access this file, and here it tells you more  

play05:41

information about what that command does and here  you can see a full description of what it does,  

play05:46

and you can see all of the different options  that you have when you run this command.

play05:51

Back now in the terminal, to clear it out,  the easiest way to do that is you could  

play05:55

simply type in clear, press enter, and  that gives you a fresh view once again.

play05:59

Here once again I have the following  directory with all of the files that  

play06:02

make up the Kevin Cookie Company website  and I want to use Git to track these files.

play06:09

So, let's take a moment to look at this address  

play06:11

here and just remember where  all of these files are stored.

play06:14

It's likely in a different location on  your computer, so just make note of that.

play06:18

Back here within Git Bash, we need to change the  directory to look at where we have those files.  

play06:24

To change the directory, let's type in  CD, that stands for change directory,  

play06:28

and then let's type in the location. I have it in  C:/users/Kevin and then Kevin Cookie Company.com

play06:38

Now I can press on enter and here we see that  it's now looking at this location on my computer.  

play06:43

To now turn this into a Git  repository, I simply type in git,  

play06:47

initialize or init, and then  I could simply press enter.

play06:52

And here we see that it's now  initialized this repository.

play06:56

Look at that, we've now created our very  first repository. Back within File Explorer,  

play07:02

it doesn't look like anything changed, but  here if I click on view and I'll go down to the  

play07:08

option that says show and here I can show hidden  items, and here there's now a new folder called  

play07:14

.git. I can now click on that, and this  contains all of the necessary repository files.  

play07:20

Back within Git Bash, we're now going to  enter a command that you'll likely use often.

play07:26

Type in git status and this will tell  us the status of our repository. When  

play07:32

I press enter, here I can see that  I'm currently on the main branch.  

play07:36

Remember at the very beginning,  we set main as our default branch.

play07:40

Here I can see that there are currently no commits  yet, and don't worry, we'll get into what that is  

play07:45

in a little bit. And down below, I see that  there are currently four untracked files.

play07:50

These are all of the files  that we saw in File Explorer.

play07:53

Currently all of my files are untracked.

play07:57

That means if I make any changes to any of these  files, Git won't care because they are untracked.

play08:04

Now if I track a file, Git will know  what changes I make to that file.

play08:08

So, let's say I want to revert  back to a previous version.

play08:11

I can do that.

play08:13

So how do we track a file? To track a file,  I can simply type in git add and then I could  

play08:19

specify the filename. So, let's say that  first I want to track the index.htm file.

play08:25

Here I'll simply type in  index.htm and then hit enter.

play08:28

So, this file is now being tracked.  To confirm that it's being tracked,  

play08:33

once again, we could use the  command that we used earlier.

play08:36

I can type in git status, hit  enter, and here I see that one  

play08:39

file is currently being tracked and we  continue to have three untracked files.

play08:44

Now let's say that for whatever reason,  I no longer want to track a file.

play08:49

Right up here, I see the tracked file  and right up above that I see a command  

play08:53

that I can use to unstage or  basically untrack this file.

play08:57

I can type in git rm for remove  --cached and then the filename.

play09:01

So, let's try this out.

play09:03

I'll type in git rm --cached,  and here let's type in index.htm,  

play09:09

then I'll hit enter. Now once again, let's  type in git status, hit enter and once again  

play09:14

we're back to the original state where all  four of my files are currently untracked.

play09:18

When I look at all of the different files that Git  

play09:21

knows about, here one of the files  is called Employee Salaries.txt.

play09:25

And I definitely don't want to  risk having anyone see this file.

play09:29

In fact, I would prefer to have Git  just completely ignore this file.

play09:33

Let's open up File Explorer  to see how we can ignore it.

play09:37

In File Explorer, we're going  to create a new file called  

play09:41

.gitignore. This allows us to ignore certain  files, folders, or even just entire extentions.

play09:48

Here I’ll right click and let's go to new and  I'll create a new text document. Right here,  

play09:55

let's select the name and the extension and let's  re-title this .gitignore and then hit enter.

play10:02

Here it tells me that it might become unstable  if I also change the filename extension.

play10:07

Let's click on yes.

play10:08

And here I have a new file called .gitignore.

play10:13

I'll take Notepad here and let's  open this file in Notepad or  

play10:16

you could use whatever text editor you want,  and currently there's nothing in this file,  

play10:21

so I need to tell git what files  or folders that I want to ignore.

play10:26

Here I'll add a comment by entering in the hash  symbol and I'll type in ignore all .txt files.

play10:33

Remember, the employee salaries is a .txt file.  

play10:37

Underneath that, here I could type in an asterisk,  so basically any filename .txt, I want to ignore.

play10:44

Now I can go to file and save. To see a  comprehensive list of all of the different  

play10:50

ways that you can ignore files, folders, or  even just entire extensions, you can go to  

play10:55

the website down below. This is ideal for things  like log files or auto generated files that you  

play11:00

don't want to include as part of your project,  or in this case, maybe you just don't want to  

play11:04

show employee salaries. Back within Git Bash,  let's see if Git is in fact ignoring that file.

play11:10

Once again, just like we've been doing  all along, we can type in git status  

play11:14

and then hit enter, and here I  no longer see employee salaries.

play11:18

I really dodged a bullet there.

play11:20

To give us a little bit more  space, let's clear out this view.  

play11:24

Now that we're ignoring one of the files,  I want git to track all of the other files.

play11:29

Earlier we tracked that one file  index.htm, but then I also untracked it.

play11:33

So how do I just rrack all of the files.

play11:36

Here I could type in Git add –all,  and that'll track all the files.

play11:41

Alternatively, I could also type in -A or I could  even simply type in . for the entire directory.

play11:48

Those are all different ways that I can  track all of the files. Here I'll press enter  

play11:53

and let's check what happened.

play11:54

Once again, let's type in Git status, hit enter,  

play11:57

and here I can see that all of these files  are currently being tracked except for that  

play12:01

file that I ignored, and currently all  of these files are in an environment  

play12:05

called staging. Now that I've added all of  these different files, I want to commit them.

play12:12

So, what does it mean to commit?

play12:15

To commit, you're taking a snapshot of  your repository at this point in time.

play12:22

Basically, what all of your  files look like right now.

play12:26

In a sense, it's like writing  an entry into a history book,  

play12:30

and if you ever want to go back to this  point in the future, you could do that.

play12:35

To commit them, we could use the commit command.

play12:38

I'll type in Git commit -m,  

play12:41

and then open quotes and here I can type  in a message to go along with this commit.

play12:47

Now remember when we commit something that's  like writing the current state of all of these  

play12:51

different files to the history books, and  this message will go along with that entry.  

play12:56

Here, I'll say this is my first commit and let's  say committing all files to the repository.

play13:04

Then I'll close my quotes  and here I can press enter.

play13:07

Congratulations, you just  finished your first commit,  

play13:11

and there's now a page in the history book.

play13:14

That wasn't so bad, was it?

play13:16

And just like that, I've now committed  all four of these files and they are now  

play13:20

officially part of the Git record.

play13:22

Here I could type in Git status once again and I  see that there are no longer any files to commit.

play13:28

Let's say I now want to change one of my files.

play13:32

I want to modify the index.htm file.

play13:35

Here I'll click on this file,  and I'll drag it into Notepad,  

play13:39

and here we see the contents of the file.

play13:41

Now, if you remember, we say eggs from chickens  that listen to classical music, but I've recently  

play13:46

found out that that's actually not true, so let me  remove this reference and maybe we just say that  

play13:53

are, let's say, free range, and next I could go  up to file and I can now save this file. Back  

play14:01

within Git, I can now type in Git status,  hit enter, and Git recognizes that one of  

play14:06

these files has been modified. To see what's  been modified, Git has a command for this.

play14:11

We could simply type in Git diff, and this  will show us what the differences are.

play14:16

I'll hit enter and right here,  if I scroll up just a little bit,  

play14:20

here we can see what the file name is, and  here I can see the original text in red  

play14:24

and here I can see the changed text in green,  so once again the red text shows that listen  

play14:30

to classical music and down here in the  green text, we see that are free range.

play14:35

I'm satisfied with all of  these changes, and once again,  

play14:37

I want to add this change to the history books.

play14:40

Let's once again type in Git add index.htm.

play14:45

The file is now currently sitting in staging.

play14:49

Staging is a place where your files  sit until you're ready to commit them.

play14:54

In a sense, it's kind of like a  holding pen until you're ready to  

play14:58

add that entry to the history books. In  Git, you have three different environments.

play15:04

You have your working files where  you can make edits to files.

play15:08

Then you have staging, and once again, this is  that holding pen until you're ready to add it  

play15:13

to the history books. And then you have your  third environment or where you commit things,  

play15:18

and this has now been added as a log  or an entry into the history books.

play15:23

Let's say I want to remove this file from staging.

play15:26

Maybe I'm not ready to commit it.

play15:29

I could type in the command, Git  restore --staged, and then index.htm.

play15:36

Now, once I press that, this moves  that file back to my working files.

play15:40

So, if I were to commit now, this file would  

play15:43

not be included because this file was  currently in the working environment.

play15:48

So, let's say that maybe you're working on 6  files and let's say that three of them you're  

play15:53

ready to commit. You can move those three  to staging and then you could commit them  

play15:57

and the files that are currently in the  working files, those would not be included.

play16:01

The index.htm file is once again in my working  files, but I do actually want to commit it.

play16:08

So once again, I could add it back to staging  and then I could commit it from staging.

play16:12

But I could also just bypass or  skip over staging altogether.

play16:17

To do that, let's simply type in Git commit –a -m,  and here I could say updated text to free range.

play16:25

Then I can close my quotes and now when I  hit enter, this skips over the staging step  

play16:30

and it's now committed this change. Here  within my git repository, I have one file  

play16:36

called Secret Recipe and I definitely don't want  that falling into the wrong hands, so I should  

play16:42

probably just delete the file, and I can do that  directly through Git. I could type in Git rm,  

play16:47

rm for remove and then I could type in the file  name Secret Recipe.htm and then close my quotes.

play16:53

But an even easier way to do that,  just directly in File Explorer,  

play16:57

I could also delete the file right  here and now that file is gone.

play17:01

Back within the terminal, let's type in Git status  and then hit enter, and here Git recognizes that  

play17:08

this file has been deleted and the reason why is  this is one of the files that Git is tracking.

play17:15

On second thought, maybe I should keep this file.

play17:18

I personally haven't memorized  the secret recipe yet.

play17:21

And right up here, I see a helpful  hint. If I want to restore this file,  

play17:26

I could type in Git restore and then  the file name. So, let's test that out.

play17:30

I'll type in Git restore, and here I'll insert  quotes and let's type in Secret Recipe.htm  

play17:36

and then close quotes and hit enter.

play17:38

If I go back to File Explorer,  look at that, the file is now back.

play17:43

Now once again, this is one of the  advantages of working with Git.

play17:47

If you've ever previously committed  a file, you can always go back to a  

play17:52

previous version, or you can recover  that previous version if you need to.

play17:56

Similar to deleting a file if you want  to rename a file, you can either do that  

play18:00

directly in File Explorer, or you  could do that back in the terminal.

play18:04

Let's try renaming a file in the terminal.

play18:06

I’ll type in Git mv, and we're using mv, and that  stands for move, so we're basically moving from an  

play18:13

old filename to a new filename. Here, I'll type in  the original filename and that's KCC logo.png and  

play18:22

I want to move to the new name primary logo.png,  then I'll close my quotes and let's hit enter.

play18:29

If we go back to File Explorer, here I can  see that the file name has been updated.

play18:34

I want to add this change to the history books.

play18:37

Basically, I want to add an entry that  says that this file name has been changed.

play18:41

I'll type in Git commit -m and then  here I could type in the message.

play18:47

So, let's say we changed  the file name of an image,  

play18:52

and then I'll close my quotes and here I could  hit enter and that has now been committed.

play18:57

So far, we've made a number of different commits,  

play19:00

or basically entries to the  history book or the log.

play19:05

What if we want to review all the  different commits that we've made?

play19:08

We could type in the command  Git log and then press  

play19:12

enter. And here we see all the different commits.

play19:15

Every single commit has a unique identifier.

play19:18

Here we also see the author and if you remember at  the very beginning, we defined who the author is.

play19:24

So, I typed in Kevin Stratvert and then  we also typed in an e-mail address.

play19:28

Then I could also see the  associated date with this commit.

play19:32

So here at the top we go with the most  recent, all the way down to the oldest  

play19:36

commits and right here I can also see the  text that I typed in as part of that commit.

play19:42

If I want a more abbreviated version of this  view, I could type in Git log --oneline,  

play19:49

and then I could hit enter and here we see an  abbreviated version of all the commit history.

play19:53

Now looking at this commit history, I just  noticed that I typed in this text incorrectly,  

play19:59

and I could go back and commit again  and then type in the text properly,  

play20:03

but I actually just want to amend that text.

play20:06

Luckily, with Git we can do that.

play20:08

I'll type in Git commit –m and  here I'll say changed file name  

play20:15

to primary logo.png and then close my quotes  and at the very end of this commit command,  

play20:21

I could type in --amend and then press  enter and that's now amended that entry.

play20:28

Now here I could press the arrow up icon  on my keyboard and I could go through  

play20:32

all the different previous  commands that I've entered.

play20:35

I could go up to Git log --oneline, hit enter,  and here you see that that text has now been  

play20:41

corrected, so that's a really neat way that you  can just go back and quickly amend a previous  

play20:45

commit without having to submit yet another  commit into the history books. I have all of these  

play20:51

different commits, but let's say I want to see  what actually changed in these different commits.

play20:55

I mean I have some text here, but what  if I want to dig into these specifics.

play21:00

Here I could type in Git log –p,  

play21:03

and then hit enter, and here I can look through  and see all of the different changes. Here for  

play21:09

example, I can see in the most recent commit,  I changed the file name to primary logo.png.

play21:15

And here I can see that I updated text to  free range and if I press my arrow key down,  

play21:20

here I can see what the original text  was, and I can see what the new text was  

play21:24

and if I press my arrow key down some  more, here I can see my very first commit  

play21:28

where I added all of these different  files to the Git repository.  

play21:33

To exit this view, I can press Q on my keyboard,  Q for quit and that exits out of this view.

play21:39

Git log has all sorts of advanced capabilities.  You could search for specific text. You could  

play21:44

look for changes that happen before a  certain date or even after a certain date.

play21:49

Now once again, as we looked at earlier, if  you want to find out the full capabilities,  

play21:53

you could type in Git help log and then hit enter.  This once again opens up the manual for Git log,  

play22:01

and here you can see the description and  here you could go through to see all the  

play22:05

different capabilities of how you could  find specific changes in your commits.

play22:10

One of the great things about having this commit  history is you can always jump back to previous  

play22:14

commits. To do that you simply type in Git  reset and then you can type in the hashtag.

play22:21

So here for instance, if I wanted to  jump to updated text to free range,  

play22:24

I could simply type in this value  here and that would bring me back.

play22:28

Now of course, I don't want to do  that, so I'm going to remove this.

play22:32

You also have the option to modify what appears  in the history book and also the order in which  

play22:38

all of these commits appear, and you can  do that using something called rebasing.

play22:42

Here I could type in Git rebase  -i --root and then hit enter.

play22:49

This brings me into an editor.

play22:51

Here I see my three commits and  then I have all of these different  

play22:54

options to modify the way things appear.

play22:56

Once again, I can change the order.

play22:58

I can even merge together  or squash two these commits.

play23:02

Now this is beyond the scope of this video  today, but I wanted to let you know that this  

play23:06

is possible. To exit this view, press the colon  key, then X, and hit enter and that brings us back  

play23:12

into the main terminal view. So far,  we've been making all of our changes  

play23:17

just directly to the main branch, but  you can also set up additional branches.

play23:24

What is another branch?

play23:26

Another branch is basically a copy of your  main branch, and it has all the same entries  

play23:32

in that history book, but this allows you  to go off and work on let's say a feature  

play23:37

or maybe you're fixing a bug and you can make all  your changes and it won't affect the main branch.  

play23:44

Once you're satisfied with all of your changes,  you can then merge it back into the main branch.

play23:49

This is also how software  development typically works.

play23:52

You'll have developers and maybe one’s working  on a new feature. They'll create a new branch to  

play23:56

work on that new feature. Maybe someone else  is working on a bug fix and they'll create  

play24:00

another branch to work on that bug fix,  and once they finish all of their work and  

play24:04

they're satisfied with how it looks, they can  merge that back into main. Here in File Explorer,  

play24:10

there’s a file called Secret Recipe and this has  the Kevin Cookie Company secret recipe in it.

play24:16

Now I probably shouldn't be showing you this,  

play24:18

but we've been working a bit  together now and I trust you.

play24:23

Let's click into this file.

play24:25

Here within the secret recipe,  all of this looks pretty good,  

play24:28

and this is a really good chocolate chip  cookie recipe. But right down here I see  

play24:32

that it calls out heating the oven to 500  degrees Fahrenheit. That's extremely hot,  

play24:39

and that would probably burn the cookies. I  need to change this to 375 degrees Fahrenheit.

play24:45

Let's create another branch to make this change,  and once we're satisfied with the change,  

play24:50

then we can merge it back onto the  main branch. To create a new branch,  

play24:55

I’ll type in Git branch and now I can type in  a name for this new branch. I want to update or  

play25:02

fix the temperature. I'll type in FixTemp and then  press enter, so now we should have two branches.

play25:09

To confirm how many branches we have, I  can type in Git branch and then hit enter  

play25:14

and here I can see that there's one branch called  

play25:16

FixTemp and there's another branch  that we're currently in called main.

play25:20

How do I know that we're currently in main,  right over here I see an asterisk next to main,  

play25:25

indicating that this is the currently active  branch. To switch into the other branch,  

play25:30

let's type in Git switch and then  I can type in FixTemp and hit  

play25:34

enter and here it says that  we've switched to branch FixTemp.

play25:39

Once again, I can type in Git branch and then  hit enter, and here I see that FixTemp is the  

play25:45

currently active branch, and here I see the  asterisks indicating that. I've opened up File  

play25:49

Explorer and all of the files that you see here in  the repository, these reflect the FixTemp branch.

play25:57

Now I want to edit the secret recipe temperature.

play26:00

I'll take this file and I'll drag it  over into Notepad and here I can see  

play26:05

the contents of secret recipe. Now once again,  I want to change the temperature down here.

play26:10

Currently it says 500. Let's change that to  375 and then click on save. Back now within  

play26:16

Git Bash let's check the status of this branch.  I’ll type in git status and then hit enter.

play26:22

And here I can see that there is  one modified file for secret recipe.

play26:26

We just updated the temperature  so that makes sense.

play26:29

Now I want to commit this change to this branch.  Just like we did before, let's type in Git commit  

play26:37

–a -m, and then here I'll say updated temp for  baking instructions, then I'll close the quotes  

play26:45

and hit enter, and that has now  committed the change to this branch.

play26:50

Next, let's switch back to main.

play26:52

Here I'll type in git switch main, then hit  enter. Here within File Explorer, because  

play26:58

we switched back into main, all of these files  reflect the current state within the main branch.

play27:04

So here if I click into secret recipe, here  we'll see that it still refers to 500 degrees  

play27:09

Fahrenheit. We only changed it in the FixTemp  branch, so we now need to bring those changes  

play27:15

from FixTemp back into main, or essentially, we  need to merge those changes in. To merge all of  

play27:22

the changes back in, let's type in Git merge -m  and here we can type in a message for this merge.

play27:29

I'll type in merge FixTemp back  to main and then close my quotes.

play27:33

Then I also need to specify what  branch I want to merge back into main.

play27:38

Here I'll type in FixTemp and then  hit enter and there I can see that the  

play27:42

file has now been merged back into main.  Here in File Explorer, in the main view,  

play27:47

I can now click on the secret recipe and here  I can see that the change has been merged in  

play27:53

and here main is now referring to 375  degrees Fahrenheit for the oven temperature.

play27:59

Now that we've merged all of the changes from  FixTemp back into main, we no longer have any  

play28:04

need for that additional branch, and at this  point, we can simply delete that branch.  

play28:09

To delete a branch, let's type in Git branch,  

play28:13

then enter -d and then you can type in  the branch name that you want to delete.

play28:18

I'll type in FixTemp and then hit enter  and that branch has now been deleted.

play28:22

Let's type in Git branch and here I can  see that I only have one branch left and  

play28:28

that's the main branch and that's also the  branch that we are currently in. Overall,  

play28:32

this merge went pretty smoothly.

play28:35

Nothing had changed in main so it was  really easy to bring our changes back in.

play28:40

But what if you create a branch and  then you try to merge it back in  

play28:44

but main has changed since  you created your branch.

play28:47

In that case, you'll have a merge  conflict, so let's see how that works.

play28:51

And first, let's create another branch.

play28:54

Here I'm going to use a command that  not only switches me to the new branch,  

play28:58

but it also creates the new branch.

play29:00

I'll type in git switch –c, the c will  create the new branch and let's call this one  

play29:07

UpdateText and then hit enter. Once  again, to confirm that we have in fact  

play29:12

switched to a new branch, I could type in Git  branch and then hit enter and here once again  

play29:17

I can see that we have two separate branches  and we're currently in the UpdateText branch.

play29:22

Here in File Explorer, once again,  all of the files that you see here  

play29:26

reflect the UpdateText branch.

play29:28

I want to make some edits  to the index.htm file. Here,  

play29:32

I'll take the file and I'll drag it into  Notepad so I can make some tweaks to it.

play29:37

Here we refer to the finest ingredients, but I  think I'd prefer to say the best ingredients,  

play29:43

and here I'll save the index.htm file, and back  within Git Bash, let's now commit these changes.

play29:50

Here I'll type in Git commit  

play29:53

and then I'll type in -a -m and here I'll  say update index text and then hit enter.

play30:00

Let's now switch into main and  we'll make a change there as well.

play30:04

Here I'll type in git switch main and  then hit enter. Here in File Explorer,  

play30:10

this now represents the main view, and here I want  to make a similar change to the index.htm file.

play30:16

Here I'll select the file and  I'll drag it over to Notepad,  

play30:20

and here it refers to the finest ingredients.

play30:23

Let's say maybe the most amazing ingredients  and then I'll save this file and close it.  

play30:29

Back now in Git Bash, let's  commit these changes to main.

play30:32

I'll type in Git commit –a and then  -m and here once again I'll say update  

play30:39

index text and then I'll hit enter. So,  I've now committed this change to main.

play30:45

Let's now try merging the changes  from UpdateText back to main to see  

play30:50

what happens. To merge UpdateText to main,  let's type in Git merge and then UpdateText,  

play30:56

and let's see what happens when we press enter.

play30:59

When I press enter, here I get an error message  telling me that the merge failed and the reason  

play31:04

why is that there are conflicts and right  down here in the bottom right-hand corner,  

play31:08

I can see that I'm currently in  a branch called main merging.

play31:12

Let's go back to File Explorer to see if  I could resolve these merge conflicts.  

play31:16

Here in File Explorer, I can see all  of the files for the merging view,  

play31:20

and if you remember, we had a merge  conflict with the index.htm file.  

play31:25

Here, I'll drag that file into Notepad and  here I can see some text that says head.

play31:30

Head refers to what's the current  reality or what's currently  

play31:35

in main and down below I could see  the text that I'm trying to bring in  

play31:39

from the branch UpdateText, and I  could decide which one I want to keep.

play31:44

Now I want to keep the text from UpdateText, so  

play31:47

here I'll delete the head and here I'll delete  this portion and then I'll save the file.

play31:53

Let's go back to Git Bash.

play31:54

Back in Git Bash, I can now commit the  change. Just like we've done before,  

play31:58

I could type in Git commit –a  -m, and then update text on  

play32:05

index and then I can close my quotes and hit  enter and that's now updated that merge conflict.

play32:10

So that's one way you can  resolve your merge conflicts.

play32:14

And now that I've resolved that conflict,  here I could see that I am now back in main.

play32:18

This should give you an idea of the  typical flow that most people use in Git.

play32:23

You have some feature or bug  that you need to work on.

play32:26

So first you'll create another branch.

play32:29

Then you'll go in and you'll  make all of your changes.

play32:32

Then you can merge it back into the main branch.

play32:35

And once you do that, then you'll delete  the branch that you were working on.

play32:39

Now that you understand the fundamentals of  working with Git, you might be wondering, well,  

play32:45

how do you work together  and collaborate with others?

play32:49

So far, we've just been working with  a Git repository that's hosted on your  

play32:54

local computer, but you can also host  your Git repository in the cloud,  

play33:01

and one of the most popular cloud  repositories is called GitHub.

play33:06

Not only do they offer a cloud repository,  but you could also manage your project.

play33:11

You could set up Kanban boards.

play33:12

You can track issues.

play33:14

You could assign features  or bugs to different people.

play33:17

In a sense, it's a social coding website. Let’s  check out how you can get started with GitHub?

play33:24

First, we need to create a GitHub account.

play33:27

You could head to the following website.

play33:29

You can click on a link up above or  also down below in the description.

play33:33

On the home page, type your e-mail address to  kick off the flow for creating a new account.

play33:39

Once you finish setting up a new  account, we can now create a cloud repo.  

play33:44

Over on the left-hand side, you should  see the option to create a new repo.

play33:49

Alternatively, you can also head to the URL  

play33:52

GitHub.new and that'll also  drop you on the new repo page.

play33:56

Let's click on this.

play33:58

You might be wondering, do I really need to  

play34:00

create a cloud repo, especially if  you just plan on working by yourself?

play34:04

Well, if you're planning on working with a team,  

play34:06

it makes sense to set up a cloud  repo so you can all work together.

play34:10

But even if you plan on just working by yourself,  by storing it in the cloud, if something happens  

play34:16

to your local computer, you have a backup, and all  of your repo files are safe. To set up a new repo,  

play34:22

over here I need to enter in a name for this  repo. I'll type in KevinCookieCompany.com.

play34:28

Down below I could also type  in a description for this repo.

play34:32

I'll leave it blank for now.

play34:34

Here I could decide, do I want to  make this repo public so anyone  

play34:37

can come in and access it or  do I want to make it private?

play34:41

If I make it private, I could assign  different individuals access to my repo,  

play34:46

so I could just work with  a smaller group of people

play34:49

Down below I also have some other  options. Here I could add a readme file.

play34:53

I could also add a gitignore file.

play34:55

Remember earlier when we  were working with our repo,  

play34:58

we manually created a gitignore file,  but here you could just create one  

play35:02

as you create your repo and down below  you could also choose to add a license.

play35:07

Now all this looks good, let's  click on create repository.

play35:11

Now that we've finished creating our  repository, here I see a quick setup guide.  

play35:17

Right here, I can see how to create  a new repository on the command line.  

play35:22

Right here, I see the option to push an  existing repository from the command line.

play35:27

We already have a repository on our local  computer that we've been working with  

play35:32

for most of this video. We can take that  repository and we can push it into the cloud.

play35:38

So, let's take this first command.

play35:40

Git remote add origin and then this URL.

play35:43

Your URL will be specific to your GitHub account.

play35:46

Let's copy this and then go back to Git Bash.  Within Git Bash, here you can right-click and  

play35:51

you can paste, or you can press shift and insert  to paste what we just copied. Right here, this  

play35:57

is establishing a remote connection with GitHub  and we're calling this remote connection origin.

play36:03

That's a common name that  most people end up using,  

play36:06

and here we can see what the address  is that we're going to connect to.

play36:10

Here I'll press enter.

play36:11

Let's now go back to the website  to see what the next command is.

play36:15

The next command will set  the target branch to main.

play36:19

Let's copy this and then go back to  Git Bash and here I'll paste this in  

play36:23

and then let's run that command as well.

play36:25

Once again, let's go back to GitHub  

play36:28

and here we can now push all the contents  from our local repository to the cloud.

play36:33

I'll copy this and then let's paste this  in and once again, let's press enter.

play36:39

And here I can see that my entire  local repository has now been pushed  

play36:44

to GitHub into the cloud  repository. Back on GitHub,  

play36:48

here I can click on the repository name  KevinCookieCompany.com and check that  

play36:53

out. Here I can now see all the files from my  repository synced onto GitHub. That's pretty cool.

play36:59

Right up here, I see that there's  currently only one branch,  

play37:02

and I had another branch called UpdateText.

play37:06

If we go back to you Git Bash, I could  also push through all of my branches.

play37:10

Here I could type in Git push --all, and that'll  push through all of my branches to GitHub.

play37:17

Let's press that. And here I can see that it  also passed through the UpdateText and branch.

play37:22

Let's go back to GitHub. Here within GitHub, I  can see now that there are two separate branches.

play37:26

I have my main branch and then I also  have the other branch titled UpdateText.

play37:31

Now that we're on GitHub, let's take a  look around to see what we can do. Here,  

play37:35

I can click on my different files, so  let's say I click on my primary logo.png.

play37:40

Here I can preview what that  looks like. Here I'll go back.

play37:44

Right here I could also see what the last  change or commit was for a specific file.

play37:50

So right here with the secret recipe, here I could  see that we updated the temperature for the baking  

play37:54

instructions. Here if I click on that, I could  review what it was and what it was changed to.

play37:59

So here I could view that log or  the git log of all of the changes.

play38:04

Back on the main screen, if I  want to add additional files here,  

play38:07

I can simply drag and drop them onto GitHub  or I can click on add a file right up here.

play38:12

Let's say I want to edit one of these files.

play38:14

Here I can click on the file name secret  recipe and here I can click on this edit icon,  

play38:20

and I can go through and make changes  directly in here and once I'm all done,  

play38:24

I could also commit directly on GitHub.  Back on the main repository view over on  

play38:30

the right-hand side, here I could  edit details about this project.

play38:33

I could click on this settings gear, and I  could type in a description, the website.

play38:37

I could enter various topics and here I could  decide whether I want to include releases,  

play38:42

packages, or environments directly here on the  repository home screen. Up across the top of the  

play38:48

page, we have all of these different tabs related  to the project and the first one is called issues.

play38:54

Let's click into this one.

play38:56

Issues is where you can enter in feature  requests or maybe someone finds a bug.

play39:01

You could enter the details of  that directly into this page.

play39:04

So, let's say that on the homepage, I notice  that we say that we get our sugar from India,  

play39:10

but it turns out we also  get it from the Philippines.

play39:12

So that's a bug on our homepage. Right over here,  let's click on new issue. On the issues page,  

play39:19

over here, I can give this issue a title, and let  me type out we should call out that organic sugar  

play39:24

comes from India and the Philippines. Over here I  could also type in additional details or comment.  

play39:31

Over on the right-hand side, I  can assign this issue to someone.

play39:35

Now currently there's no one else on my team,  so I’ll assign it to myself just so I can keep  

play39:39

track of this issue. Down below, I could also  assign a label. I'll click on the settings gear  

play39:44

and here I can add a bug, but you  have all these other labels as well.

play39:48

I'll select bug. Right here I  could also assign it to a project.

play39:52

I could also assign various milestones.

play39:55

And I'm all done entering in the details  here, so let's click on submit new issue.  

play40:00

This has now successfully created an issue  and the great thing in GitHub is, it's a  

play40:06

social environment so other people could come in  here, they can leave a comment. We could discuss  

play40:10

is this truly a bug that needs to be fixed  and maybe what priority should we give it?  

play40:15

We can have that discussion all  right here within this page.

play40:19

Now I have this issue assigned to  myself, so I should probably get  

play40:22

to work and update our index page  to also call out the Philippines.  

play40:27

In the top left-hand corner, let's click on the  code tab, and right here I have my index file.

play40:32

I want to edit this. I’ll click on index.htm  and over here let's click on this edit icon.  

play40:38

Within the edit view, right up here let's  change it so it wraps. So here I can see all  

play40:43

the text on this page, and if I look right  here it calls out organic sugar only from  

play40:49

India. And of course, we also  get it from the Philippines,  

play40:52

so here I'll say and the Philippines.  Now I'm all done making my changes.

play40:59

If I scroll down just a little bit here, I  could commit it directly to the main branch  

play41:04

or I have the option to create a new branch  for this commit and to start a pull request.

play41:10

So, what is a pull request?

play41:12

Well, I can start a new pull request and  then this change has to be approved. So,  

play41:17

especially if you're working with others, you can  have other people go in. They can make changes  

play41:22

and then you can have them submit a pull request,  

play41:24

so the change has to be reviewed by someone  before you push it through to the main branch.

play41:30

I'll give this new branch a name.

play41:31

I'll call it IncludePhilippinesSugar  and then click on propose changes.

play41:36

This has now successfully created a new  branch called IncludePhilippinesSugar  

play41:41

and now I want to submit a pull request.

play41:44

This is basically a request for someone  to approve merging this back to main.

play41:49

Right down below, I can see  the pull request details.

play41:52

It says update index.htm, but I probably  want to be a little bit more explicit.

play41:57

I'll insert a - and maybe include some text that  

play42:00

says we should include Philippines as one  of the countries that we get sugar from.

play42:04

All of this now looks good.

play42:05

Let's click on create pull request.

play42:08

This has now successfully created a pull request  so we could go through and have a discussion  

play42:13

about the merits of this change and if everything  looks good, we can then merge the pull request.

play42:19

Over on the right-hand side, there's a section  called development, and when I click on this  

play42:24

settings gear, I can tie this change, or  this pull request back to the original issue.

play42:30

So, here's the issue that I called out  where we missed calling out the Philippines.

play42:34

I select that and this is  now tied back to that issue.  

play42:38

Now if I merge this pull request, here  I'll confirm the merge. Not only will  

play42:44

it merge this back into main, but it'll  also close out the corresponding issue.

play42:49

Let's go up to the top of the page and click into  issues and here you'll see because I accepted that  

play42:54

pull request or that change, it has automatically  closed that open issue. Here if I click into  

play43:00

closed, here I could review that bug that came  in and look at that we're getting work done.

play43:06

That one is all done. Up at the  very top, there are a few more tabs.

play43:10

There's one called actions, and this is where you  

play43:13

can run different tests. You can basically  write programs to manage your repository.

play43:19

There’s another tab called projects, and  this is basically a project management view  

play43:24

where you can view all of your  issues, view all your pull requests,  

play43:27

you can filter the different views. It  makes it really easy to manage your project.

play43:32

There’s another tab called Wiki, and  this is where you can document your code.

play43:36

It's kind of like Wikipedia, but for your  project. There’s another tab called security,  

play43:42

and this is where you could manage all  of your different policies. You can  

play43:44

define what should happen when let's  say a vulnerability is discovered.

play43:48

You could also set up scanning,  if that's what you want.

play43:51

There’s another tab called  insights, and this is where you can  

play43:55

see,well who's contributing to your  project. What does the traffic look like?  

play43:58

How many issues have been closed? How many commits  have there been? How many people are contributing?

play44:04

You can view all of that right here.

play44:06

And lastly, there's another tab called settings,  and this is where you can configure various  

play44:11

settings related to your project. Over on the  left-hand side, if you click on collaborators,  

play44:16

here's where you can add additional  people to work with you on your project.

play44:21

Let's go back to the main repository  view and over on the right-hand side,  

play44:25

we can also create a release. Now this is V1  of our website. Let's click here on create.

play44:31

And here I can choose a tag.

play44:33

Why don't we call this release.

play44:36

And here I'll select that.

play44:37

And here I could give it a release title.

play44:39

I'll title it V1.0.0. This is just the first  iteration. Over on the right-hand side,  

play44:46

you can see some suggestions for  how you should name your release.  

play44:50

Now this all looks pretty good,  let's click on publish release.

play44:54

And look at this, we now have V1 available  and here anyone can now come in and they  

play44:59

could download the source code for  the KevinCookieCompany.com website.

play45:03

Now you might be wondering, we made  a few changes in GitHub on the cloud,  

play45:08

but how do we get those changes  back onto our local computer?

play45:11

Well, there are a few different  commands that we can use.

play45:14

First, we could use Git  fetch, and this will download  

play45:18

all the history from the remote tracking branches.

play45:21

And to merge that in we could type in Git merge  

play45:23

and that'll now merge it in with  what we have on our local machine.

play45:27

But instead of typing in those two separate  commands, we could also type in git pull,  

play45:32

and then I'll hit enter and this will download  all the files. So, it basically combines fetch  

play45:37

and merge into just one command, git pull. All  right, well hopefully now you have a strong  

play45:43

understanding of how you can get started with  both Git and also GitHub. To learn more, I've  

play45:49

included some fantastic resources down below in  the description. To watch more videos like this,  

play45:56

please consider subscribing and  I'll see you in the next video.