Git Version Control Systems (VCS) changes your approach to modern software engineering. Using Git, you can easily track the history of file and code changes, deliver new versions of software without relying on any continuous delivery mechanisms, and protect your code from any mistakes made while programming.
In this course, we’ll teach you the basics of using Git and explain how it works. To begin with, we’ll show you how to install Git and effectively use your computer’s terminal or command line to navigate the file system, and create and edit files. Then we’ll cover all the commonly used commands in Git that make up the vast majority of any Software Engineer’s workflow.
Moving on, we’ll explain Git’s branching workflow, why it’s such a useful feature, and how to use it in your projects. Once you’ve learned all this, we’ll discuss some advanced Git workflow techniques that will make you a valued contributor and collaborator on any project. You’ll be able to create your own Git repositories, or clone and contribute to existing ones. This will allow you to track the changes to sets of files over time, recover data you might lose, and collaborate with others on projects. You’ll have a profound understanding of Git’s branching workflow, and how to use it in the best possible way in your projects.
By the end, you’ll be familiar with using Git and use VCS to handle large projects easily and make well-crafted contributions to your own or others’ projects.
About the Author
High quality, professional personal development. Teclado produces training courses to expand your knowledge to new areas and learn to tackle new challenges, expertly.
Jose Salvatierra started Teclado in 2017 to bring software development to as many students as possible. Its courses help them transition to new software areas, such as backend development using Python, web development, and automated testing.
Their mission is to bring the knowledge of professional software engineers to students around the world so that students can learn the skills they need on the job with concise and straightforward screencasts.
Ross Conyers is a Computer Science Graduate and Software Engineer who started programming and building computers in his teens and went on to study Computer Science at the University of St Andrews. When he started programming, he worked with web technologies and Java. During his degree, he focussed on network programming and have developed a love of all things. Throughout his work, he did programming mostly in Python, working on high traffic, data-intensive, distributed systems that are used by millions of people per day. He believes to share some of his knowledge gained within the several years.
Version Control and the Terminal
This video provides an overview of the entire course.
Learn what Version Control is as a concept, what it is used for, and why it can be so useful for software developers.
Overview of Version Control as an abstract concept
Look at an outline of Version Control’s major benefits
Explain why Git is our chosen VCS system
Learn how to install Git on your machine, be it OS X or Windows.
Download the installer for your operating system
Run the installer
Configure Git on your machine
The terminal is a text-based interface to our computer and operating system. It will be the primary method of interaction with Git in this course.
Explain the reasons for using the terminal
Outline the terminal’s capabilities for OS interaction and control
Handle “falsey” expressions in an else block
Filesystem navigation is one of the most important skills to have when using the terminal. Navigating to different folders and listing their contents is a fundamental part of most terminal usage.
Navigate between different locations in the filesystem
List the contents of directories
View help files for terminal commands
Consider the following: creating a folder, moving a file or folder to a different location, copying a file, renaming a file, or reading its contents using a few simple commands. These operations can be very useful if you want to make some quick changes to your filesystem without using your file explorer.
Learn about various file and folder manipulation commands
Practice the use of the commands
Vi is a very powerful command-line text editor that allows users to edit and read any text files directly from the command line.
Learn about VI as an editor
Open and edit a new file using VI
Learn how to quit VI
Learning the Basics of Git
The git init command can be used to turn any folder on your computer into a Git repository. This will be the starting point for our Git learnings.
Initialize a repository on your computer
Observe what this command does under the hood
Tracking files is the process of telling a Git repository to track the changes made to those files over time.
Tell Git to track specific files
Learn the different stages that changes can be in
A key component of Git is viewing the changes you have made to files since your last commit. To do this, we can use the Git diff command.
Make some changes to the repo
Run the Git diff command
View the diff output
Once changes have been made in the repository, we will want to save those changes. To do this, we use the Git commit command.
Make and view your changes using Git diff
Save those changes to the repository using Git commit
Provide a useful message to the commit
There will be files in our Git repositories that we will not want to track the changes to, such as build artefacts. We can use Git ignore lists to specify these files.
Decide what files are to be ignored
Create a .Gitignore file in the repository
Write an expression to match the filenames of ignored files
The main focus of Git is to track changes to files over time. To view all changes committed to a repository over a certain time period, we can use the Git log command.
Open a repository that has been committed to
Use Git log to view all changes
Pass arguments to filter the log to your liking
Sometimes when programming, we introduce bugs that break the software we work on. Git can be used to easily revert the change that broke the program.
Identify the commit to be reverted
Use Git revert to undo the mistake
Commit the revert
We won’t always start the projects we work on from our own machines. To begin working on an existing repository, we can clone the repository using Git clone.
Get the URL of the repository you want to clone
Clone it to your local machine
Start working on your clone of the repo
In order to share work with other programmers, we need to send to and pull changes from remote repositories. We can manage our repositories’ remotes using the Git remote command.
Use Git remote to show our configured remote repositories
Add or remove remotes
Fetch and merge changes into your local repository
Sometimes we might want to designate a certain commit as one of significance, for example, a certain released version. We can do this using Git tags.
Add tags to certain commits with messages
Push the tags to remote repositories
Show the commit a tag points to
Branches and Workflows
Branches can be used to enable parallel, simultaneous workflows in a single repository.
Learn how they are represented by Git
Learn why they are so useful
Branches can and should be used often to enable parallel workflows and allow developers to work independently in the same repo. The Git branch command can be used to create new branches.
Check out the branch you want to branch from
Use Git branch command to create new branch
Check out the new branch and begin working
Once our work has been completed on a separate branch, we will want to add that code back to the main branch of the repository. To do this, we use the Git merge command.
Check out the branch you want to merge into
Use the Git merge function
Commit the changes to the repo
Sometimes, automatic merges will not be possible due to changes having been merged into the repository that our changes conflict with. To fix this, we need to follow the conflict resolution workflow.
Initiate the merge process using the Git merge command
Manually choose which changes to merge into the master branch
Commit the resolved merge changes to the repository
When working with remotes, we need branches that track their equivalent branch on the remote repo. These are called remote tracking branches.
Create new branch on the local repo
Push the branch to the remote repository
See other collaborators fetching your branch and track it
Sometimes we will want to incorporate new changes from the branch we branched from into our feature branch. To do this, we can use the Git rebase command.
Check out the feature branch to rebase
Use the Git rebase command with the target branch
Continue to work with new changes incorporated into the feature branch
Advanced Git Workflow
Sharing code repositories with others requires us to host the remote repository somewhere where it is is mutually accessible. GitHub can be used to do this.
Create a repository on GitHub
Push code to the remote repository
Have others clone and work on the repository
When contributing changes to existing repositories we may not always have write access, and may need to create a copy to work on. This can be done using forking.
Create a fork of the repository to contribute to
Create changes on the forked repository
Keep the fork up to date by adding upstream remote
When contributing to any repository, we should structure our commit messages well. This helps other collaborators understand the intention behind our contributions, and aids the “debugability” of our changes.
Use a clear structure for commit messages
Keep commits messages succinct and commits logically separate
When working on our local repository, we may make several commits that create one logically distinct contribution. Before pushing our changes to the remote, we can squash those commits into one single commit for simplicity.
Create multiple commits on the local repository
Squash several commits into one logically distinct unit
Push squashed commits to the repo
Once we have created some changes on our forked repo, we will want to contribute those changes back into the original repository. To do this, we can use a merge request.
Push local changes to our repository fork
Open a merge request with the original repository
Get the changes merged into the original repository
Sometimes, we may want to customize our Git workflow and create shortcuts for common tasks. To do this, we can create aliases in Git.
Think of the command you want to alias
Add the alias to your global Git config
Use the shorter command to save time and effort