├── README.md ├── Week 1 ├── 1. diff and patch cheat sheet.txt ├── 2. Practice Quiz Before Version Control.txt ├── 3. Practice Quiz Version Control Systems .txt ├── 4. Initial Git Cheat Sheet.txt ├── 5. Practice Quiz using git.txt └── 6. Qwiklabs Assessment Introduction to Git.txt ├── Week 2 ├── 1. Advanced Git Cheat Sheet.txt ├── 2. Practice Quiz Advanced Git Interaction.txt ├── 3. Git Revert Cheat Sheet.txt ├── 4. Practice Quiz Undoing Things .txt ├── 5. Git Branches and Merging Cheat Sheet.txt ├── 6. Branching and Merging Quiz.txt └── 7. Qwiklabs Assessment Merging Branches in Git .txt ├── Week 3 ├── 1. Basic Interaction with GitHub Cheat-Sheet.txt ├── 2. Practice Quiz Introduction to GitHub.txt ├── 3. Git Remote Cheat Sheet.txt ├── 4. Practice Quiz Using a Remote Repository.txt ├── 5. Conflict Resolution Cheat Sheet.txt ├── 6.Practice Quiz Solving Conflicts.txt └── 7. Qwiklabs Assessment .txt └── Week 4 ├── 1.Practice Quiz Pull Requests .txt ├── 2. Practice Quiz Code Reviews.txt ├── 3. Practice Quiz Managing Collaboration.txt └── 4. Qwiklabs Assessment .txt /README.md: -------------------------------------------------------------------------------- 1 | # Ultimate Git Cheat Sheet , Author : PaareshC 2 | =========================================================== 3 | 4 | Remember : 5 | > The only way to master Git is through Practice 6 | 7 | ## Configuring you Git 8 | 9 | | Syntax | Description | 10 | | :--- | :--- | 11 | | $ git config --global user.name "Username" | Sets the name you want attached to your commit transactions | 12 | | $ git config --global user.email "Email" | Sets the email you want attached to your commit transactions | 13 | | $ git config --global color.ui auto | Colorization of command line output | 14 | 15 | 16 | ## Creating Repository 17 | 18 | | Syntax | Description | 19 | | :--- | :--- | 20 | | $ git init | Turn an existing directory into a git repository | 21 | | $ git clone [url] | Clone a repository that already exists on GitHub | 22 | 23 | 24 | ## Operations on Files 25 | 26 | | Syntax | Description | 27 | | :--- | :--- | 28 | | $ git add | Adds a file to Staging area | 29 | | $ git add * | Adds all files to Staging area | 30 | | $ git commit -a | Stages files automatically | 31 | | $ git log -p | Produces patch text | 32 | | $ git show | Shows various objects | 33 | | $ git diff | Can show the differences in various commits | 34 | | $ git diff --staged | Show all staged files compared to the named commit | 35 | | $ git add -p | Allows a user to interactively review patches to add to the current commit | 36 | | $ git mv | Moves a file | 37 | | $ git rm | Removes a file | 38 | 39 | 40 | ## Reverting Changes 41 | 42 | | Syntax | Description | 43 | | :--- | :--- | 44 | | $ git reset | Resets the repo, throwing away some changes | 45 | | $ git commit --amend | Make changes to commits | 46 | | $ git revert | New commit which effectively rolls back a previous commit | 47 | 48 | 49 | ## Branches 50 | 51 | | Syntax | Description | 52 | | :--- | :--- | 53 | | $ git branch | Used to manage branches | 54 | | $ git branch | Creates the branch | 55 | | $ git branch -d | Deletes the branch | 56 | | $ git branch -D | Forcibly deletes the branch | 57 | | $ git checkout | Switches to a branch | 58 | | $ git checkout -b | Creates a new branch and switches to it | 59 | | $ git merge | Merge joins branches together | 60 | | $ git merge --abort | abort the merge action (In case of merge conflict) | 61 | | $ git log --graph --oneline | This shows a summarized view of the commit history for a repo | 62 | 63 | 64 | ## Interaction with Remote Repository 65 | 66 | | Syntax | Description | 67 | | :--- | :--- | 68 | | $ git push | Git push is used to push commits from your local repo to a remote repo | 69 | | $ git pull | Git pull is used to fetch the newest updates from a remote repository | 70 | 71 | 72 | ## Remotes 73 | 74 | | Syntax | Description | 75 | | :--- | :--- | 76 | | $ git remote | Lists remote repos | 77 | | $ git remote -v | List remote repos verbosely | 78 | | $ git remote show | Describes a single remote repo | 79 | | $ git remote update | Fetches the most up-to-date objects | 80 | | $ git fetch | Downloads specific objects | 81 | | $ git branch -r | Lists remote branches; can be combined with other branch arguments to manage remote branches | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Week 1/1. diff and patch cheat sheet.txt: -------------------------------------------------------------------------------- 1 | diff and patch Cheat Sheet 2 | diff 3 | 4 | diff is used to find differences between two files. On its own, it’s a bit hard to use; instead, use it with diff -u to find lines which differ in two files: 5 | diff -u 6 | 7 | diff -u is used to compare two files, line by line, and have the differing lines compared side-by-side in the same output. See below: 8 | 9 | ****************************************** 10 | ~$ cat menu1.txt 11 | Menu1: 12 | 13 | Apples 14 | Bananas 15 | Oranges 16 | Pears 17 | 18 | ~$ cat menu2.txt 19 | Menu: 20 | 21 | Apples 22 | Bananas 23 | Grapes 24 | Strawberries 25 | 26 | ~$ diff -u menu1.txt menu2.txt 27 | --- menu1.txt 2019-12-16 18:46:13.794879924 +0900 28 | +++ menu2.txt 2019-12-16 18:46:42.090995670 +0900 29 | @@ -1,6 +1,6 @@ 30 | -Menu1: 31 | +Menu: 32 | 33 | Apples 34 | Bananas 35 | -Oranges 36 | -Pears 37 | +Grapes 38 | +Strawberries 39 | 40 | ****************************************** 41 | 42 | Patch 43 | 44 | Patch is useful for applying file differences. See the below example, which compares two files. The comparison is saved as a .diff file, which is then patched to the original file! 45 | 46 | 47 | ****************************************** 48 | 49 | ~$ cat hello_world.txt 50 | Hello World 51 | ~$ cat hello_world_long.txt 52 | Hello World 53 | 54 | It's a wonderful day! 55 | ~$ diff -u hello_world.txt hello_world_long.txt 56 | --- hello_world.txt 2019-12-16 19:24:12.556102821 +0900 57 | +++ hello_world_long.txt 2019-12-16 19:24:38.944207773 +0900 58 | @@ -1 +1,3 @@ 59 | Hello World 60 | + 61 | +It's a wonderful day! 62 | ~$ diff -u hello_world.txt hello_world_long.txt > hello_world.diff 63 | ~$ patch < hello_world.diff 64 | patching file hello_world.txt 65 | ~$ cat hello_world.txt 66 | Hello World 67 | 68 | It's a wonderful day! 69 | 70 | 71 | ****************************************** 72 | 73 | There are some other interesting patch and diff commands such as patch -p1, diff -r ! 74 | 75 | Check them out in the following references: 76 | 77 | http://man7.org/linux/man-pages/man1/diff.1.html 78 | http://man7.org/linux/man-pages/man1/patch.1.html 79 | 80 | 81 | -------------------------------------------------------------------------------- /Week 1/2. Practice Quiz Before Version Control.txt: -------------------------------------------------------------------------------- 1 | Q 1) Your colleague sent you a patch called fix_names.patch, which fixes a config file called fix_names.conf. What command do you need to run to apply the patch to the config file? 2 | Ans) patch fix_names.conf fix_permissions.patch 6 | 7 | Q 3) The _____ commandhighlights the words that changed in a file instead of working line by line. 8 | Ans) wdiff 9 | 10 | Q 4) How can we choose the return value our script returns when it finishes? 11 | Ans) Using the sys command from exit module 12 | 13 | Q 5) In addition to the original files, what else do we need before we can use the patch command? 14 | Ans) diff file 15 | -------------------------------------------------------------------------------- /Week 1/3. Practice Quiz Version Control Systems .txt: -------------------------------------------------------------------------------- 1 | Q 1) How can a VCS (Version Control System) come in handy when updating your software, even if you’re a solo programmer? Check all that apply. 2 | Ans) -Git retains local copies of repositories 3 | -If something breaks due to change, you can fix problem by reverting to a working version before the change 4 | -Git allows you to review the history of your project 5 | 6 | Q 2) Who is the original creator and main developer of the VCS (Version Control System) tool Git? 7 | Ans) Linus Torvaldo 8 | 9 | Q 3) _____ is a feature of a software management system that records changes to a file or set of files over time so that you can recall specific versions later. 10 | Ans) Version Control 11 | 12 | Q 4) A _____ is a collection of edits which has been submitted to the version control system for safe keeping. 13 | Ans) Commit 14 | 15 | Q 5) Within a VCS, project files are organized in centralized locations called _____ where they can be called upon later. 16 | Ans) Repositories -------------------------------------------------------------------------------- /Week 1/4. Initial Git Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | Links 2 | 1) https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=HEAD 3 | 2) https://commit.style/ 4 | 3) https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message 5 | 4) https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address -------------------------------------------------------------------------------- /Week 1/5. Practice Quiz using git.txt: -------------------------------------------------------------------------------- 1 | Q 1) Before changes in new files can be added to the Git directory, what command will tell Git to track our file in the list of changes to be committed? 2 | Ans) git add 3 | 4 | Q 2) Which command would we use to review the commit history for our project? 5 | Ans) git log 6 | 7 | Q 3) What command would we use to make Git track our file? 8 | Ans) git add 9 | 10 | Q 4) Which command would we use to look at our config? 11 | Ans) git config -l 12 | 13 | Q 5) Which command would we use to view pending changes? 14 | Ans) git status -------------------------------------------------------------------------------- /Week 1/6. Qwiklabs Assessment Introduction to Git.txt: -------------------------------------------------------------------------------- 1 | DO ON YOUR OWN TO CLARIFY YOUR CONCEPTS -------------------------------------------------------------------------------- /Week 2/1. Advanced Git Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | Command Explanation & Link 2 | git commit -a Stages files automatically 3 | git log -p Produces patch text 4 | git show Shows various objects 5 | git diff Is similar to the Linux `diff` command, and can show the differences in various commits 6 | git diff --staged An alias to --cached, this will show all staged files compared to the named commit 7 | git add -p Allows a user to interactively review patches to add to the current commit 8 | git mv Similar to the Linux `mv` command, this moves a file 9 | git rm Similar to the Linux `rm` command, this deletes, or removes a file 10 | 11 | There are many useful git cheatsheets online as well. Please take some time to research and study a few, such as this one. 12 | .gitignore files 13 | 14 | .gitignore files are used to tell the git tool to intentionally ignore some files in a given Git repository. For example, this can be useful for configuration files or metadata files that a user may not want to check into the master branch. Check out more at: https://git-scm.com/docs/gitignore. 15 | 16 | https://gist.github.com/octocat/9257657 -------------------------------------------------------------------------------- /Week 2/2. Practice Quiz Advanced Git Interaction.txt: -------------------------------------------------------------------------------- 1 | Q 1) Which of the following commands is NOT an example of a method for comparing or reviewing the changes made to a file? 2 | Ans: git mv 3 | 4 | Q 2) What is the gitignore file? 5 | Ans: A file contiaining a list of files or filnames patterns for Git to skip for current repo. 6 | 7 | Q 3) What kind of file will the command git commit -a not commit? 8 | Ans: New files 9 | 10 | Q 4) What does HEAD represent in Git? 11 | Ans: The currently checked out snapshot of your project 12 | 13 | Q 5) If we want to show some stats about the changes in a commit, like which files were changed and how many lines were added or removed, what flag should we add to git log? 14 | Ans: --stat -------------------------------------------------------------------------------- /Week 2/3. Git Revert Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | git checkout is effectively used to switch branches. 2 | 3 | git reset basically resets the repo, throwing away some changes. It’s somewhat difficult to understand, so reading the examples in the documentation may be a bit more useful. 4 | 5 | There are some other useful articles online, which discuss more aggressive approaches to resetting the repo. 6 | 7 | git commit --amend is used to make changes to commits after-the-fact, which can be useful for making notes about a given commit. 8 | 9 | git revert makes a new commit which effectively rolls back a previous commit. It’s a bit like an undo command. 10 | 11 | There are a few ways you can rollback commits in Git. 12 | 13 | There are some interesting considerations about how git object data is stored, such as the usage of sha-1. 14 | 15 | Feel free to read more here: 16 | 17 | https://en.wikipedia.org/wiki/SHA-1 18 | https://github.blog/2017-03-20-sha-1-collision-detection-on-github-com/ -------------------------------------------------------------------------------- /Week 2/4. Practice Quiz Undoing Things .txt: -------------------------------------------------------------------------------- 1 | Q 1) Let's say we've made a mistake in our latest commit to a public branch. Which of the following commands is the best option for fixing our mistake? 2 | Ans: git revert 3 | 4 | Q 2) If we want to rollback a commit on a public branch that wasn't the most recent one using the revert command, what must we do? 5 | Ans: Use commit ID at the end of git revert 6 | 7 | Q 3) What does Git use cryptographic hash keys for? 8 | Ans: To guarantee consistency of our repository 9 | 10 | Q 4) What does the command git commit --amend do? 11 | Ans: Overwrite the previous commit 12 | 13 | Q 5) How can we easily view the log message and diff output the last commit if we don't know the commit ID? 14 | Ans: git show -------------------------------------------------------------------------------- /Week 2/5. Git Branches and Merging Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | Command Explanation & Link 2 | git branch Used to manage branches 3 | git branch Creates the branch 4 | git branch -d Deletes the branch 5 | git branch -D Forcibly deletes the branch 6 | git checkout Switches to a branch. 7 | git checkout -b Creates a new branch and switches to it. 8 | git merge Merge joins branches together. 9 | git merge --abort If there are merge conflicts (meaning files are incompatible), --abort can be used to abort the merge action. 10 | git log --graph --oneline This shows a summarized view of the commit history for a repo. 11 | 12 | -------------------------------------------------------------------------------- /Week 2/6. Branching and Merging Quiz.txt: -------------------------------------------------------------------------------- 1 | Q 1) When we merge two branches, one of two algorithms is used. If the branches have diverged, which algorithm is used? 2 | Ans: three-way merge 3 | 4 | Q 2) The following code snippet represents the result of a merge conflict. Edit the code to fix the conflict and keep the version represented by the current branch. 5 | Ans: print("Keep me!") 6 | 7 | Q 3) What command would we use to throw away a merge, and start over? 8 | Ans: git merge --abort 9 | 10 | Q 4) How do we display a summarized view of the commit history for a repo, showing one line per commit? 11 | Ans: git log --graph --oneline 12 | 13 | Q 5) The following script contains the result of a merge conflict. Edit the code to fix the conflict, so that both versions are included. 14 | Ans: def main(): 15 | print("Start of program>>>>>>>") 16 | print("End of program!") 17 | 18 | 19 | main() -------------------------------------------------------------------------------- /Week 2/7. Qwiklabs Assessment Merging Branches in Git .txt: -------------------------------------------------------------------------------- 1 | DO ON YOUR OWN TO CLARIFY YOUR CONCEPTS -------------------------------------------------------------------------------- /Week 3/1. Basic Interaction with GitHub Cheat-Sheet.txt: -------------------------------------------------------------------------------- 1 | There are various remote repository hosting sites: 2 | 3 | GitHub 4 | BitBucket 5 | Gitlab. 6 | 7 | Follow the workflow at https://github.com/join to set up a free account, username, and password. After that, these steps will help you create a brand new repository on GitHub. 8 | 9 | Some useful commands for getting started: 10 | Command Explanation & Link 11 | git clone URL Git clone is used to clone a remote repository into a local workspace 12 | git push Git push is used to push commits from your local repo to a remote repo 13 | git pull Git pull is used to fetch the newest updates from a remote repository 14 | 15 | This can be useful for keeping your local workspace up to date. 16 | 17 | https://help.github.com/en/articles/caching-your-github-password-in-git 18 | https://help.github.com/en/articles/generating-an-ssh-key -------------------------------------------------------------------------------- /Week 3/2. Practice Quiz Introduction to GitHub.txt: -------------------------------------------------------------------------------- 1 | Q 1) When we want to update our local repository to reflect changes made in the remote repository, which command would we use? 2 | Ans : git pull 3 | 4 | Q 2) git config --global credential.helper cache allows us to configure the credential helper, which is used for ...what? 5 | Ans : Allowing Automated Login to GitHub 6 | 7 | Q 3) Name two ways to avoid having to enter our password when retrieving and when pushing changes to the repo. 8 | Ans : Use Credential Helper or use SSH key-pair 9 | 10 | Q 4) Name the command that gathers all the snapshots we've taken and sends them to the remote repository. 11 | Ans : git push -------------------------------------------------------------------------------- /Week 3/3. Git Remote Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | Git Remotes Cheat-Sheet 2 | 3 | Command Explanation & Links 4 | git remote Lists remote repos 5 | git remote -v List remote repos verbosely 6 | git remote show Describes a single remote repo 7 | git remote update Fetches the most up-to-date objects 8 | git fetch Downloads specific objects 9 | git branch -r Lists remote branches; can be combined with other branch arguments to manage remote branches -------------------------------------------------------------------------------- /Week 3/4. Practice Quiz Using a Remote Repository.txt: -------------------------------------------------------------------------------- 1 | Q 1) In order to get the contents of a remote branch without automatically merging, which of these commands should we use? 2 | Ans: git remote update 3 | 4 | Q 2) If we need to find more information about a remote branch, which command will help us? 5 | Ans: git remote show origin 6 | 7 | Q 3) What command will download remote branches from remote repositories without merging the content with your current workspace automatically? 8 | Ans: git fetch 9 | 10 | Q 4) What type of merge creates a new merge commit? 11 | Ans: Explicit merge 12 | 13 | Q 5) What method of getting remote contents will automatically merge the remote branch with the current local branch? 14 | Ans: git pull -------------------------------------------------------------------------------- /Week 3/5. Conflict Resolution Cheat Sheet.txt: -------------------------------------------------------------------------------- 1 | Merge conflicts are not uncommon when working in a team of developers, or on Open Source Software. Fortunately, GitHub has some good documentation on how to handle them when they happen 2 | 3 | httpshelp.github.comengithubcollaborating-with-issues-and-pull-requestsabout-merge-conflicts 4 | httpshelp.github.comengithubcollaborating-with-issues-and-pull-requestsresolving-a-merge-conflict-using-the-command-line 5 | 6 | You can also use git rebase branchname to change the base of the current branch to be branchname -------------------------------------------------------------------------------- /Week 3/6.Practice Quiz Solving Conflicts.txt: -------------------------------------------------------------------------------- 1 | Q 1) If you’re making changes to a local branch while another user has also made changes to the remote branch, which command will trigger a merge? 2 | Ans : git pull 3 | 4 | Q 2) Which of the following is a reason to use rebase instead of merging? 5 | Ans : When you want to keep a linear commit history 6 | 7 | Q 3) Where should we keep the latest stable version of the project? 8 | Ans : A separate branch from the master 9 | 10 | Q 4) Which of the following statements represent best practices for collaboration? (check all that apply) 11 | Ans : a.It makes sense to have separate feature branch 12 | b.Always sync your branches before starting your won work 13 | c.Avoid having large changes that modify lot of things 14 | 15 | Q 5) What command would we use to change the base of the current branch? 16 | Ans : git rebase 17 | 18 | -------------------------------------------------------------------------------- /Week 3/7. Qwiklabs Assessment .txt: -------------------------------------------------------------------------------- 1 | DO ON YOUR OWN TO CLARIFY YOUR CONCEPTS -------------------------------------------------------------------------------- /Week 4/1.Practice Quiz Pull Requests .txt: -------------------------------------------------------------------------------- 1 | Q 1) What is the difference between using squash and fixup when rebasing? 2 | Ans : Squash combines the commit messages into one. Fixup discards the new commit message 3 | 4 | Q 2) What is a pull request? 5 | Ans : A request send to owner and collaborators of the target repository to pull your recent changes 6 | 7 | Q 3) Under what circumstances is a new fork created? 8 | Ans : When you want to experiment with changes without affecting the main repository . 9 | 10 | Q 4) What combination of command and flags will force Git to push the current snapshot to the repo as it is, possibly resulting in permanent data loss? 11 | Ans : git push -f 12 | 13 | Q 5) When using interactive rebase, which option is the default, and takes the commits and rebases them against the branch we selected? 14 | Ans : pick -------------------------------------------------------------------------------- /Week 4/2. Practice Quiz Code Reviews.txt: -------------------------------------------------------------------------------- 1 | Q 1) When should we respond to comments from collaborators and reviewers? 2 | Ans : Always 3 | 4 | Q 2) What is a nit? 5 | Ans : A trivial comment or suggestion 6 | 7 | Q 3) Select common code issues that might be addressed in a code review. (Check all that apply) 8 | Ans : a.Using unclear names 9 | b.Forgetting to add tests 10 | c.Forgetting to handle a specific condition 11 | 12 | Q 4) If we've pushed a new version since we've made a recent change, what might our comment be flagged as? 13 | Ans : Outdated 14 | 15 | Q 5) What are the goals of code review? (Check all that apply) 16 | Ans : a.Make sure that contents are easy to understand 17 | b.Ensure consistent styles 18 | c.Ensure we don't forget any important cases -------------------------------------------------------------------------------- /Week 4/3. Practice Quiz Managing Collaboration.txt: -------------------------------------------------------------------------------- 1 | Q 1) How do we reference issues in our commits with automatic links? 2 | Ans : By using one of the keywords followed by a hashtag and the issue number 3 | 4 | Q 2) What is an artifact in terms of continuous integration/continuous delivery (CI/CD) pipelines? 5 | Ans : Any file generated as part of CI/CD pipeline 6 | 7 | Q 3) Which of the following statements are good advice for project maintainers? (Check all that apply) 8 | Ans : b.Reply promptly to pull requests 9 | c.Understand any changes you accept 10 | d.Use an issue tracker 11 | 12 | Q 4) Which statement best represents what a Continuous Integration system will do? 13 | Ans : Run tests automatically 14 | 15 | Q 5) Which statement best represents what a Continuous Delivery (CD) system will do? 16 | Ans : Update with incremental rollouts 17 | -------------------------------------------------------------------------------- /Week 4/4. Qwiklabs Assessment .txt: -------------------------------------------------------------------------------- 1 | DO ON YOUR OWN TO CLARIFY YOUR CONCEPTS --------------------------------------------------------------------------------