From the course: Working with LinkedIn Learning Exercise Files on GitHub

Understand the basic Git command workflow - GitHub Tutorial

From the course: Working with LinkedIn Learning Exercise Files on GitHub

Understand the basic Git command workflow

- [Instructor] Git has many commands, but you don't need to know all of them to work with course repositories. If you know how to clone a repo and check out branches, that's 95% of what you need to be successful. The other commands you might need in some scenarios are diff, commit, stash and restore. Use clone to copy an existing repository into a new directory. When a repository is cloned to your computer, it is known as the local repository. It's important to note that you get the entire repository including all branches and the entire historical record of the changes made to the repository. In most situations, you'll clone once when you start the course. In a repo with multiple branches, use git checkout to switch to another branch. Checkout can also be used at a more granular level than a branch, for example, it can be used to check out one or more files or check out an individual commit. For LinkedIn Learning courses, use checkout branch. Git diff shows the differences between two sources. The sources could be two branches or two commits. Diff is useful to compare your work with the instructor files or compare different branches in the course files to see what has changed as the course progresses. Now, let's look at some commands to help you preserve any modifications you make. What I'm talking about here is when you check out a branch edit some of the files in the branch and save your changes. Your modified files are saved to your hard drive but they are not saved to the repository or to say it another way, you haven't told git what to do with the modified files. There are several options available, some Git commands to consider it but first, let's talk about the opposite scenario. For people who check up branches, inspect the contents and don't modify files, it's easy to switch between the branches. On the other hand, if you modify the contents of the branch you must decide what to do when it's time to switch branches. Git will warn you that there are changes and won't let you proceed with the checkup until you've dealt with the issue. These are the more common ways to deal with modified content. You can commit the changes to the current branch. This is useful if you want to keep your changes in the branch, but the side effect of this is you've moved the original instructor content into the branch history. Once you're committed, you can switch to the other branch. Another side effect is that it's additional work to get the instructor's original code back. A better solution is used Git stash to store the pending changes in a temporary area in the repository. Once you've stashed, you're checked out branch is reset to the original state and you can switch to the other branch. Your changes are safe in the stash and all the branches in the repo match the initial repo state. Later, you can pop the stash to see your modifications. Another choice is to use, git restore to undo all the pending changes and roll back to the original version. Once you've restored, you can switch to the other branch. In this scenario, you've intentionally thrown away all your modifications. This is a popular options for some scenarios. We've all been in the situation where we've unintentionally changed a file save the changes, and then want to undo if so, restore is your new friend. You'll see how to use all the commands mentioned in this video later in the course.

Contents