You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

136 lines
22 KiB

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Learning Website</title>
<link href="/styles/styles.css" rel="stylesheet" type="text/css">
<link href="/webdevelopment/styles/styles.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="banner">
<h1 class="courselink_small">Programming Foundations: Version Control with Git</h1>
<h2 class="lecturer">LinkedIn Learning : Christina Truong</h2>
<h2 class="episodetitle">Introduction to Version Control</h2>
</div>
<article>
<h2 class="sectiontitle">Git: Basic Concepts</h2>
<p>One of the most fundamental features of version control is that it tracks chamges amd maintains a version history <strong>within the same file</strong>. This is very important because if you do this manually, you would usually have multiple copies of the file with names like v1.index.html. The important point is that with version control, there is no need to adopt some kind of naming convention that allows you to distinguish between the different versions of the file.</p>
<p>If you make changes to a file, you can commit these to the repository and later, if you want to remove the changes, you can do that by reverting to an older version of the file.</p>
<p>I think that it is fairly obvious that this provides you with an advantage when we are talking about a single file or, for instance, a web page with three files (HTML, CSS and JavaScript) but you could argue that it is not a huge improvement on just using different copies of the file with different names.</p>
<p>It might be worth pointing out that when I mention version control in the course, I don't just mean some means of providing version control. In this example, using different files with different names is actually a rudimentary form of version control and it does, for instance, allow you to revert to an earlier version of a file simply by renaming an older file.</p>
<p>Consider this, let's say you have a file called index.html. You want to update it so you make a copy which you name index.html.v1 and you edit the original file. This might go on until you have, let's say, 6 versions of the file. The live version is just called HTML and the older versions have v1 up to v5 appended to the filename. If you want to revert to the third version of the file, you simply copy it over to index.html. That's nice and straightforward, but it does mean that as well as discarding any changes in the live file that were made since you created index.html.v5 (the latest version apart from index.html), you will also lose any changes that were added in versions 4 and 5 and simply be reverting to the third version.</p>
<p>If you want to incorporate some (but not all) of the changes from version 4 or some (possibly all) of the changes from version 5, you will have to do that manually.</p>
<p>This can be hard to keep track of because you now have multiple copies of the file and your 'latest' copy doesn't include some of the changes you had subsequently made (although to be fair, you may encounter this sort of problem with any type of version control.</p>
<p>So, when we talk about version control in this course, we mean some method that does all of this tracking for you (unless I am explicitly referring to this manual version control). Since the course is about Git, you can assume that Git and version control are synonyms but some of the information will also apply to other version control systems.</p>
<p>A version control system uses a concept known as a commit. This means that you can edit a file as much as you want, but it doesn't become the latest version of the file until you commit it to the repository. If you want to revert to an earlier form of the file, you can check out previous versions, edit them and commit this back to the repository making it the new latest version (you could also think of it as the live version in some circumstances.</p>
<p>Another concept that is very important in version control is branches. Any project stored in Git will have at least one branch which is referred to as the Master Branch. If you want to make changes, you can do that by editing the latest version of the file in the master branch (or by editing an older version if you need to revert to one before making the changes) so all of these changes remain inside the master branch.</p>
<p>If you want to experiment, you will probably want to make changes to one or more files and have them committed, for example, if you are working on a website and you want to upload it to the web server for testing. You will probably also want to keep the original files intact. If we go back to our manual version control, we can do that by simply copying the files into a new location where we can edit them without changing our original files. In version control, this is achieved by creating a branch where we can make these changes. If we want to add these changes into the master branch, we can merge the new branch with the master branch. If not, we can either keep the two branches separate or delete the unwanted branch.</p>
<p>As you can see, we can maintain some sort of version control either manually or by using a version control system such as Git. As you are reading this, you might be tempted to think that there is not really much difference between the two and learning a system like Git adds some overhead to the whole process, so why would you want to use a system like Git. There are two reasons and one is project complexity. When we are talking about a very small project like this example, there is very little overhead involved in manually maintaining the different versions of the files and this may mean that the additional overhead involved in using Git is not worth the effort. Just as a quick side issue, for this site, I have lots of files. Currently, I have around 700 files which includes HTML files as well as CSS, JavaScript, image and other files.</p>
<p>Most of the HTML files follow a basic set pattern so if I want to make changes to, for instance, the headers on my pages, there are a lot of files that will need to be changed. Git won't help me do that, so really, in spite of the size, the site is not really that complex. I don't really need different versions of the individual pages since they mainly contain little more than text. If I want to make different versions of the site, for instance with a different layout for my pages, a different navigation system and so on, I would most likely create a new version of the website (the current version is the fifth and the fourth since I started maintaining it with Dreamweaver.</p>
<p>Nevertheless, if a project is very complicated and you do need to track changes in a lot of files, the overhead can easily become so big that it becomes worthwhile to learn and use Git.</p>
<p>The second big advantage Git offers over manual version control is that it makes it much easier to collaborate on a project. With a service like Git, your repository will normally be hosted online somewhere so it can be accessed by as many team members as have access with each one able to check out a branch and work on it and then reintegrate it back into the main branch.</p>
<h2 class="sectiontitle">What is Git?</h2>
<p>Beyond simply saying that Git is a version control system, which it is, it's also worth considering some of the features and characteristics of Git, epecially when compared to other similar systems.</p>
<p>One important distinction when considering the difference between systems is whether it is centralised or distributed. A good example of a centralised version control system is subversion. All of the files associated with a project are stored on a central server. A user will check out the files that he wants to work on and when finished, these files will be sent back to the server (via a commit) which will update the version numbers and so on.</p>
<p>There are some disadvantages to this kind of system.</p>
<pre class="inset">
&bull; The user has to have a connection to the server in order to check out the files.
&bull; He will only have access to the files that he is working on rather than the whole project.
&bull; Since you need to access the server to check out the files, if the connection to the server goes down, he will not have access to them.</pre>
<p>In coontrast, Git is a distributed system and this type of system is designed to combat some of the disadvantages of a centralised system. Some of the avantages with this type of system are</p>
<pre class="inset">
&bull; A developer can have an entire copy of the project and version history store locally.
&bull; Optionally, a central location for storage of the project and be designated, allowing users to access the files remotely and so facilitating the ahring of files.
&bull; Potentially a big advantage, you only ever need to connect to the server when you want to sync any changes between your computer and the remote directory.</pre>
<h2 class="sectiontitle">Git Concepts and Terminology</h2>
<p>It might be helpful to cover some of the other concepts associate with a version control system before we dive into using Git. First of all, I should mention that I have been using the full name, but you will commonly see a version control system referred to as simply a VCS.</p>
<pre class="inset">
&bull; SCM - this stands for Source Code Manager. It's really just another name for a VCS although you should remember that a VCS may be used to track something other than source code. So essentially, an SCM is a VCS, but a VCS is not always an SCM.
&bull; Repository or repo - this is like a storage are where all of your files are stored, but it also stores the information needed to track the changes in the different versions. A repo can be stored locally or remotely.
&bull; Commit - this has been mentioned previously, essentially it is the process of writing changes to a file. A commit, really, is a snapshot, much like a save position in a video game. This is one of the fundamental concepts in any VCS.
&bull; A branch - again these have been covered earlier so I probably don't need to mention it here, but I will just add that branches are sometimes referred to as feature branches. They are often used to experiment with the code so it may be a way, for example, of adding in a feature and testing it before deciding whether to add it back to the main branch. The advantage is that if the new feature causes problems or you just decide you don't want to keep it, you can just discard the branch. You don't need to remove the changes from the main branch because the changes weren't made there.</pre>
<p>The terms covered here, as well as some additional terminology is in the cheat sheet included with the exercise files.</p>
<h2>Hosting Services</h2>
<p>There are several ways in which you can store different versions of your files and this includes cloud services such as DropBox or OneDrive as well as apps that will sync your files with a backup drive to give you a locally stored respository, but these services only sync the files, they are not really giving yopu any real version control. NextCloud (and I would guess also OwnCloud) make a rudimentary VCS available to users but it is very basic.</p>
<p>By comparison, services such as GitHub, GitLab and BitBucket provide much a more comprehensive set of VCS features as well as other more advanced features such as a project wiki. In this course, the preferred choice is BitBucket so it is a good idea to sign up for a free account there. You may already have a preferred VCS, the one I have used occassionally in the past is GitHub but there is no real reason not to have multiple accounts or to use different services for different projects.</p>
<h2>Hosting Services</h2>
<p>With Git, since it is a distributed VCS, a cerntralised repository is not a requirement, but there are advantages to using one. In addition to facilitating collaboration, it also provides you with a backup that you can access from anywhere, including on different machines in your own home or office.</p>
<p>You can use a service like Google Drive or OneDrive, but these services only provide you with a syncing service, they don't really give you much else in terms of, for example, collaboration although they do allow you to share the files with other users and allow them to edit the files.</p>
<p>The one thing they really don't give you is version control so if you are using one of these services, you would be responsible for tracking the different versions and who is working on them. Incidentally, NextCloud offers a very rudimentary version control system, but it is very basic and will delete your files if they are older than a set limit or if your files use more than 50% of your allocated space so you would have to be very careful.</p>
<p>A hosting service that provides version control is better in that it gives you much more robust version control as well as all the advantages you would get from using a service such as OneDrive or NextCloud. Of course, that's not to say that you can't use both. For example, if you check out some files to a local system, there is no reason why you can't store these on OneDrive or NextCloud. The advantage here is that if you make changes to the files without commiting them, these changes will not be available to another user via your VCS, or indeed to you from another computer. Storing them on a cloud drive means that you can edit the files from different locations and they can be edited by different users before the changes are committed to the VCS.</p>
<p>There are several hosted VCS services including</p>
<pre class="inset">
&bull; GitHub
&bull; GitLab
&bull; BitBucket</pre>
<p>These services do also provide some more advanced services such as a project wiki, issue tracking and so on. The most important thing is to understand what each of these services offers and how you can make use of them in your own project so you may very well use more than one in combination or use different tools for different projects.</p>
<p>One final point I would like to make regarding a service like GitHub. I'm mentioning it here because it is the one that I am most familiar with and I don't know if this is something that the other services will do, but GitHub can be integrated into tools such as Dreamweaver and Android Studio. Since I use these tools myself, this is a strong selling point for GitHub. Actually, my interest in this course came about because I am interested in finding out how to work with GitHub in Dreamweaver.</p>
<p>This course, however, uses BitBucket. It may be worth signing up for a free account and you can do that on the <a href="https://bitbucket.org/">BitBucket</a> site. You can also download the GUI from here and access more information on the service.</p>
<p>I don't really know anything about GitLab, for example I din't know if it provides a GUI (update: it does), but you can sign up for an account on the <a href="">GitLab</a> website. It doesn't seem to offer a free account but does give you a free trial.</p>
<p>I do know that GitHub will provide you with a free account because it is the service I have used previously and you can get more information on it on the <a href="https://github.com/">GitHub</a> website.</p>
<p>Of course, LinkedIn Learning also provides additional courses on some of these subjects if you want to learn more about a specific VCS or how to use a VCS with a specific product. This includes the following:</p>
<pre class="inset">
&bull; <a href="https://www.linkedin.com/learning/dreamweaver-working-with-git-version-control">Dreameweaver: Working with Git Version Control</a> from August 2017.
&bull; <a href="https://www.linkedin.com/learning/visual-studio-source-control-with-git-and-github">Visual Studio: Source Control with Git and GitHub</a> from March 2020.
&bull; <a href="https://www.linkedin.com/learning/learning-git-and-github-14213624">Learning Git and GitHub</a> from September 2021.
&bull; <a href="https://www.linkedin.com/learning/learning-github">Learning GitHub</a> from May 2019.
&bull; <a href="https://www.linkedin.com/learning/git-essential-training-the-basics">Git Essential Training: The Basics</a> from May 2019.
&bull; <a href="https://www.linkedin.com/learning/learning-gitlab-2">Learning GitLab</a> from August 2019.</pre>
<p>I couldn't find any courses on BitBucket so you might take this as a reflection on the relative importance, or at least popularity of the different systems. There are also other courses on different aspects of using Git.</p>
<p>When it comes to using Git, a course from 2017 could be considered reasonably up to date, but Dreamweaver has changed quite a bit in that time, so if you are studying that course while using Drewamweaver 2021, you may need to spend some time figuring out how everything works in your version of Dreamweaver. For that, you will probably want to see some up to date documentation and you can find that on the Adobe site in an article entitled <a href="https://helpx.adobe.com/dreamweaver/using/git-support.html">Using Git in Dreamweaver.</a></p>
<h2 class="sectiontitle">Git Workflow</h2>
<p>The way in which you use Git will be determined by several factors such as whether you are working alone or as part of a team so there is more than one possible workflow. However, there are some basic principles that you need to be familar with and that will apply regardless of the workflow you follow.</p>
<pre class="inset">
&bull; How to create a respository
&bull; How to create a commit</pre>
<p>The workflow will be the same, regardless of whether you are using a GUI or issuing commands via the Command Line and we will look at these commands in detail later. In general, it will follow certain steps.</p>
<pre class="inset">
&bull; Step 1 - create a repository for your project and initalise Git so that it starts tracking your files.
&bull; Step 2 - make some changes. This can be any type of change including editing, creating, deleting or moving the files. Save the changes. With Git, saving a file is a multi-stage process which can involve one or multiple files.
&bull; Step 3 - add the file.
&bull; Step 4 - commit the file.
&bull; Step 5 - repeat steps 2 to 4 as necessary.</pre>
<p>The Git repository operates with three areas.</p>
<pre class="inset">
&bull; The Working Directory.
&bull; The Staging Area.
&bull; The Repository.</pre>
<p>All your work is done in the Working Directory. When you are ready to add these files to the repository, they are moved to the staging area. This is a process where you are deciding what files or even what chages you will want to commit and the files are moved to the staging area. You might consider this to be analogous to placing items in a shopping cart.</p>
<p>The staging area is really just a list of revisions that are to be committed to the repository. The fact that they have been moved to the staging area means that you intend to commit them, but doesn't actually commit them until they are moved to the repository.</p>
<p>The process of commiting the files is, essentially the process of moving from the staging area into the repository. They become part of a snapshot of the directory that is added to the version history. Once you have made the commit, you then go back to your files in the working directory and start the process again.</p>
<p>Git doesn't really have an option to undo a change or delete a commit because that's not really the point of it. It simply captures the state of your project at specific points.</p>
<h2 class="sectiontitle">Installing Git</h2>
<p>You can download Git from the <a href="https://git-scm.com/downloads">Git Downloads</a> page select the download for your OS (versions are available for Window, MacOS amd Lunix/Unix. Just a short digression, there are some additional resources that can be accessed from this page including the online version of the bookl <a href="https://git-scm.com/book/en/v2">Pro Git</a> by Scott Chacon and Ben Straub as well as a list of available <a href="https://git-scm.com/downloads/guis">GUIs</a>.</p>
<p>The installation itself is fairly standard but it may be worth noting that where you have the opportunity to select components, these include Git Bash and Git GUI which are optional. You can execute Git commands from any command line including Power Shell but Git Bash is an alternative tool for that purpose. Windows won't, by default, have a Git GUI installed so you can install the GUI here or you can install a GUI of your own choosing. In most cases, whatever options you do select can be reconfigured later.</p>
<p>You can verify the installation by opening up power shell or a command line and typing the command</p>
<pre class="inset">git --version</pre>
<p>Hopefully, this will return the version number and it will match the version number of the download. You can also use this command if you're not sure if you have Git installed already or if you want to check your version number against the latest to see if it is worth updating it.</p>
</article>
<div class="btngroup">
<button class="button" onclick="window.location.href='commandline.html';">
Next Chapter - Git and the Command Line
</button>
<button class="button" onclick="window.location.href='versioncontrolwithgit.html'">
Course Contents
</button>
<button class="button" onclick="window.location.href='/webdevelopment/webdevelopment.html'">
Web Development Page
</button>
<button class="button" onclick="window.location.href='/index.html'">
Home
</button>
</div>
</body>
</html>