From the course: Automating Kubernetes with GitOps
Git fundamentals - Kubernetes Tutorial
From the course: Automating Kubernetes with GitOps
Git fundamentals
- Okay, so what do we need to get started with Git? Well, we need to set Git client options. There are global options. Global options are written to the user's home directory in the .git config file. You can also use repository-specific options which are stored in the .git directory. If you want to see the options currently used, use git config -l --global, and that will show you all the global options. And you can set global options like your user information. Use git config --global user.name, followed by your Git username and user.email followed by the email address that's associated to your Git username. If you want to set up passwords, you'll need to use the Git client and set up a credentials case. In the next video I'll show you how to do that as well as how to use advanced Git credentials. To set options on a product-only basis, just use git config without --global. So how do we work with Git? Well, working with Git starts on the Git server where the upstream repository is created. And next the directly on the local workstation is created, an in its directory you are going to use git init. git init is what you use to create the metadata in the workstation directory. And next a README.md file is added, containing information about the contents of the Git directory. This README.md in real Git repositories is pretty important because you are going to provide your documentation in it, and based on that documentation, your users know exactly what your project is doing. Now from there, the normal Git command flow can be applied, so that will be git add to add all the files to the staging area and git commit -m "commit message" to commit these files to the head. To push files from the head to the remote repository, you use git push. And different push methods are available. You can use git config --global push.default to set the default push method. You would use push.default matching to push all branches and use push.default simple to push the current brands only. push.default simple is the recommended and default value, and you probably just want to keep it like that. Now let me demonstrate how to work with Git. Here on the slide, you can find the steps in the demo. So if you want to just pause the video at this point and work your way through these steps and then compare with what I've done. All right, so here we are in my GitHub account. I'm already logged in because I'm using this a lot. Here we can see the current signed in information and the settings is here. And what we see here is all the Git repositories that I'm using. So I want to create a new Git repository, and in order to create the new Git repository, it's not really rocket science, I'm clicking New. So here it's asking for the repository name, gitdemo. It's telling me gitdemo is available. So sandervanvugt/gitdemo is what we are going to use. You don't need anything else of what is listed here. Just click Create repository to create the repository. So next it's even telling you what to do. If you want to make it easy on yourself, just copy paste this. I don't want to copy paste this, I want to provide some insight. So at this point we're ready to move to the Linux machine and take care of the client part. Okay, so now I'm on Linux and I can set my generic parameters. So git config --global user.email followed by my email address and likewise user dot.name followed by my username. So what you see here, I'm on the Linux system. But this is not specific for Linux because we are working in the Git client. And in the Git client, well, no matter your operating system, it'll always be the same. There's one more option that I would like to set, and that is git config --global init.defaultBranch main. Now the thing is that in the past in IT, throughout different products, you would often find the name master. Master is now deprecated terminology, but if you don't change it, Git is still creating a master branch. If you don't want that to happen, then you can use this init.defaultBranch main, and that will make sure that your main branch will be made main. Okay, now I'm going to create my Git directory. So mkdir gitdemo. And I need to go in the Git directory using cd. Then git init is creating the Git metadata. So the head and the staging area, that is all in this metadata directory. You can see that if you do tree on .git, oh, we need to install that, sudo apt install tree. So now that we have installed tree, we can try it again, tree .git/, and there we can see the exact configuration that is created in this metadata environment. No worries, you won't ever work with this. But it's just cool to know that what happening behind the scenes. So let me create a file using my favorite editor. Don't be scared for Vim, you want to use nano, that's okay. It's just we need a text file. This is a demo git project. Please ignore. I'm doing this because my Git account. Well, I have people following me on Git, and they're checking out what I'm doing. So for the people using my Git repositories, this is just a matter of politeness. Next I'm using Git add *. And what is Git add * doing? Well, if you use git status, now we can see that no commits yet, and we are on the branch main and Changes this to be committed. New file: README.md. I can also unstage it using git rm --cached on this file. If I want to get it out of the staging area, which might be necessary if I need to apply more changes, for instance. Next git commit -m "initial commit" and another git status. And that is showing that we are on the branch main and Nothing to commit, working tree clean. So all files are now ready to be pushed. So how is that happening? Let me show you the second slide so that we can continue. Okay, so I'm using git branch -m main. Why is that? That's not really necessary, just to indicate that we're in main branch. And next git remote add origin, https://github.com/, my name. In my case it happens to be sandervanvugt. And something, well that's the name of the Git repo, in this case gitdemo. And now I have added the remote Git repo to my local metadata. And I can use git push --u origin main and then, oh boy, what is happening? It's prompting for a username. Now that is confusing. My username is my very secret username and my password, what password is that? Well, I can tell you if at this case you use the password that you are using to log into GitHub, you'll get the option support for password authentication was removed. And that is because or nowadays, we should use personal access tokens. And in the next video I'll explain how to use personal access tokens. So we'll be back, but let's first talk about advanced authentication.
Contents
-
-
-
-
-
(Locked)
Module 2: From code to image introduction24s
-
(Locked)
Learning objectives29s
-
(Locked)
Understanding Git6m 48s
-
Git fundamentals8m 58s
-
(Locked)
Using Git advanced authentication7m 3s
-
(Locked)
Working with branches and merges5m 46s
-
(Locked)
Organizing Git repositories for GitOps environments2m 19s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-