Final exercise project
Intro
The final step is to create a simulated project using Git and GitHub using just the CheatSheet for reference.
Use whichever of the following methods to perform Git actions that you prefer:
Initiate a Git repository.
Make a first commit.
Create a .gitignore file and put the .env file in it. If you are on a Mac, ignore .DS_Store files.
Enter command to view your files' Git status.
Make your second commit.
Go back to your local repo and add the GitHub repository as your default remote.
Make your first push to GitHub.
Enter the Git command to list your remotes including the URL.
Code the branch with the below:
Stage and commit the changes.
Checkout the main branch.
Merge the feature1 branch.
Enter Git command to see all branches.
Push to the remote.
Delete the feature1 branch.
Code the branch with the below:
Stash the changes.
Put back the stashed changes, removing the stash.
List your stashes to confirm there are none.
Stash the changes again.
Apply the stash back to your code without removing the stash.
List your stashes to confirm it is still there.
Delete the stash.
List your stashes to confirm it is gone.
Stage the changes without committing them.
Unstage the changes.
Discard all the changes.
Create feature2.txt again, stage and commit it.
List the commits, then undo the last commit putting the changes from that commit in the staging area.
Commit the changes again.
Undo the last commit again, putting the changes in the working directory.
Stage and commit the changes again.
Undo the last commit again and discard the changes.
Create feature2.txt again, stage and commit it.
Add a second line to feature2.txt then amend the previous commit to include this change.
Add third line to feature2.txt, stage and commit the change.
Add file, stage and commit it.
Create a commit that reverses the last commit (that added badfile.txt), reverting the code to what it was before the last commit.
Modify app.txt stage and commit it.
Log all commits with each commit on one line.
Log all commits with each commit on one line in graph format (i.e., branch commits indented).
Log last 5 commits.
Log all commits up to the commit tagged as feature1.
Log all commits after the commit tagged as feature1 (i.e., only the feature2 branch commits)
Open rebase interactive then abort it without changing anything.
Drop the two commits that created badfile and reversed badfile.
Combine the commit that created the feature2.txt file and the commit that added a third line to it.
Edit the feature2.txt commit. Change the feature2.txt file's last line to read:
Reorder the remaining commits.
Change the commit message on one or more of the remaining commits.
Merge the feature2 branch.
Enter the Git command to see all branches.
Push to the remote.
Delete the feature2 branch.
In your local repository, check if you are still in sync with the remote without merging it.
Use the Git command to print the differences between your local main branch and the remote's main branch.
Merge the commit from the remote into your local repo.
As a project team member:
In your local repo, confirm that you are still in sync with the remote repo.
Create and checkout a topic branch called feature3.
Code the branch with the below:
Stage and commit the changes.
Make sure your main branch is still in sync with the remote.
Push the topic branch to the remote.
Go to the remote repo and create a pull request from the topic branch.
As project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer, but understand the difference between the three:
As project team member:
Sync your local repo with the remote.
Delete the feature3 branch from your local repo.
As a contributor:
Fork the git-demo2 project. For clarity, name the repo git-demo2-fork.
Clone the git-demo2-fork repo to your computer.
In your local git-demo2-fork repo:
Set the GitHub git-demo2-fork repo as a remote named origin. This is where you push to.
Set the original GitHub git-demo2 project as a remote named upstream. This is where you pull from.
Enter the Git command to see your remotes including the URLs.
Create and checkout a new branch named feature4.Code the branch with the below:
Stage and commit the changes.
Make sure the main branch is still in sync with the original git-demo2 remote's main branch.
Go back to the feature4 branch and push it to your forked remote repo.
Go to your git-demo2-fork remote repo and create a Pull Request for the topic branch on the original git-demo2 repo.
As the project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer:
As a contributor:
In your local git-demo2-fork repo, checkout the main branch.
Get in sync with the original git-demo2 remote repo.
Get your remote git-demo2-fork repo in sync with your local repo.
Delete the feature4 branch.
A bug is found in feature4 and you are assigned to fix it.
As the project administrator:
You found a bug in feature4.
Open an issue titled Feature 4 contains a bug.
Assign the issue to yourself.
Label the issue with "bug"
As a collaborator assigned to address the issue:
Confirm your local git-demo2-fork project is still in sync with the original git-demo2 remote.
Create and checkout a branch named patch-feature4.
Code the fix with the below:
Stage and commit the change.
Confirm the main branch is still in sync with the original git-demo2 remote.
Push the patch-feature4 branch to your remote git-demo2-fork repo.
Go to your git-demo2-fork remote repo and create a Pull Request for the patch-feature4 topic branch on the original git-demo2 remote repo.
As project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer:
As the contributor:
In your local git-demo2-fork repo, checkout the main branch.
Get in sync with the original git-demo2 remote repo.
Get your git-demo2-fork repo in sync with your local repo.
Delete the patch-feature4 branch.
Go back to your local git-demo2 repo.
Sync with the remote.
Log all commits using the oneline and graph options.
Add tags for feature2, feature3, and feature4.
Push the tags to the remote.
Use the Git command to see all your branches. Keep only the main branch.
Repeat the whole process if necessary until you are comfortable with all the above actions.
Make sure you are familiar with the CheatSheet topics so you can quickly reference them in the future when needed.
Congratulations, you are now proficient with Git and GitHub!
Use whichever of the following methods to perform Git actions that you prefer:
- Git commands from the command line.
- Or VS Code Source Control toolbars and menu items.
Setup
Create a project named git-demo2.First commit
Create some files:app.txt
Main file for the app.
file1.txt
Some text.
Initiate a Git repository.
Make a first commit.
Second Commit
Add general files for the app:about.txt
About this app.
README.md
# Git Demo 2 Info about app goes here.
- Create a directory called docs and add a Markdown file in it for notes.
docs/notes.md
# Notes about this app. Put notes about app here.
- Add a file called .env that holds environmental variables for use in your app.
.env
Sensitive info goes here.
Create a .gitignore file and put the .env file in it. If you are on a Mac, ignore .DS_Store files.
.gitignore
.DS_Store .env
Enter command to view your files' Git status.
Make your second commit.
Setup Remote
Go to your GitHub account and create a new repository called git-demo2. Copy the URL.Go back to your local repo and add the GitHub repository as your default remote.
Make your first push to GitHub.
Enter the Git command to list your remotes including the URL.
Branches
Create and checkout a branch named feature1.Code the branch with the below:
feature1.txt
Some text.
App.txt
Main file for the app.
Feature 1.
Stage and commit the changes.
Checkout the main branch.
Merge the feature1 branch.
Enter Git command to see all branches.
Push to the remote.
Delete the feature1 branch.
Tags
Add a tag to the last commit named feature1.
Add a tag to the commit before the feature1 branch commits named base-app.
Push all tags to the remote.
List all your tags.
Log all your commits to confirm the tags are on them.
Add a tag to the commit before the feature1 branch commits named base-app.
Push all tags to the remote.
List all your tags.
Log all your commits to confirm the tags are on them.
Stash code
Create and checkout a branch named feature2.Code the branch with the below:
- Create feature2.txt file
feature2.txt
Some text.
- Modify app.txt
App.txt
Main file for the app.
Feature 1. Feature 2.
Stash the changes.
Put back the stashed changes, removing the stash.
List your stashes to confirm there are none.
Stash the changes again.
Apply the stash back to your code without removing the stash.
List your stashes to confirm it is still there.
Delete the stash.
List your stashes to confirm it is gone.
Git Undo/Redo
Unstage the changes.
Discard all the changes.
Create feature2.txt again, stage and commit it.
feature2.txt
Some text.
List the commits, then undo the last commit putting the changes from that commit in the staging area.
Commit the changes again.
Undo the last commit again, putting the changes in the working directory.
Stage and commit the changes again.
Undo the last commit again and discard the changes.
Create feature2.txt again, stage and commit it.
feature2.txt
Some text.
Add a second line to feature2.txt then amend the previous commit to include this change.
feature2.txt
Some text. Amended to add this line.
Add third line to feature2.txt, stage and commit the change.
feature2.txt
Some text. Amended to add this line. Third line.
Add file, stage and commit it.
badfile.txt
Some unneeded text.
Create a commit that reverses the last commit (that added badfile.txt), reverting the code to what it was before the last commit.
Modify app.txt stage and commit it.
App.txt
Main file for the app.
Feature 1. Feature 2.
Logs
Log all commits.Log all commits with each commit on one line.
Log all commits with each commit on one line in graph format (i.e., branch commits indented).
Log last 5 commits.
Log all commits up to the commit tagged as feature1.
Log all commits after the commit tagged as feature1 (i.e., only the feature2 branch commits)
Rebase Interactive
Use rebase interactive on the commits in the feature2 branch to do the following:Open rebase interactive then abort it without changing anything.
Drop the two commits that created badfile and reversed badfile.
Combine the commit that created the feature2.txt file and the commit that added a third line to it.
Edit the feature2.txt commit. Change the feature2.txt file's last line to read:
Third line edited.
Reorder the remaining commits.
Change the commit message on one or more of the remaining commits.
Finish the feature2 branch
Checkout the main branch.Merge the feature2 branch.
Enter the Git command to see all branches.
Push to the remote.
Delete the feature2 branch.
Add license to the remote repo then merge it into your local repo
Add an MIT license to the remote project.In your local repository, check if you are still in sync with the remote without merging it.
Use the Git command to print the differences between your local main branch and the remote's main branch.
Merge the commit from the remote into your local repo.
Shared Repository - Create feature3 pull request
Pretend the remote git-demo2 project is a small team project and you are one of the team members. We will simulate you playing two roles:- A project team member assigned to add a feature called feature3.
- The project administrator.
As a project team member:
In your local repo, confirm that you are still in sync with the remote repo.
Create and checkout a topic branch called feature3.
Code the branch with the below:
feature3.txt
Some text.
app.txt
Main file for the app.
Feature 1.
Feature 2.
Feature 3.
Stage and commit the changes.
Make sure your main branch is still in sync with the remote.
Push the topic branch to the remote.
Go to the remote repo and create a pull request from the topic branch.
As project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer, but understand the difference between the three:
- Create a merge commit.
- Squash and merge.
- Rebase and merge.
As project team member:
Sync your local repo with the remote.
Delete the feature3 branch from your local repo.
Fork and Pull - Create feature4 pull request
Pretend the remote git-demo2 project is an open source project. You want to propose a new feature, feature4. We will simulate you playing two roles:- A contributor to the open source project that is proposing a feature called feature4.
- The project administrator.
As a contributor:
Fork the git-demo2 project. For clarity, name the repo git-demo2-fork.
Clone the git-demo2-fork repo to your computer.
In your local git-demo2-fork repo:
Set the GitHub git-demo2-fork repo as a remote named origin. This is where you push to.
Set the original GitHub git-demo2 project as a remote named upstream. This is where you pull from.
Enter the Git command to see your remotes including the URLs.
Create and checkout a new branch named feature4.
feature4.txt
Some text.
This is a bug.
app.txt
Main file for the app.
Feature 1.
Feature 2.
Feature 3.
Feature 4.
Stage and commit the changes.
Make sure the main branch is still in sync with the original git-demo2 remote's main branch.
Go back to the feature4 branch and push it to your forked remote repo.
Go to your git-demo2-fork remote repo and create a Pull Request for the topic branch on the original git-demo2 repo.
As the project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer:
- Create a merge commit.
- Squash and merge.
- Rebase and merge.
As a contributor:
In your local git-demo2-fork repo, checkout the main branch.
Get in sync with the original git-demo2 remote repo.
Get your remote git-demo2-fork repo in sync with your local repo.
Delete the feature4 branch.
Issues
Continue pretending the remote git-demo2 project is an open source project and you have a forked remote and local copy of the repo.A bug is found in feature4 and you are assigned to fix it.
As the project administrator:
You found a bug in feature4.
Open an issue titled Feature 4 contains a bug.
Assign the issue to yourself.
Label the issue with "bug"
As a collaborator assigned to address the issue:
Confirm your local git-demo2-fork project is still in sync with the original git-demo2 remote.
Create and checkout a branch named patch-feature4.
Code the fix with the below:
feature4.txt
Some text. This bug has been patched.
Stage and commit the change.
Confirm the main branch is still in sync with the original git-demo2 remote.
Push the patch-feature4 branch to your remote git-demo2-fork repo.
Go to your git-demo2-fork remote repo and create a Pull Request for the patch-feature4 topic branch on the original git-demo2 remote repo.
As project administrator:
Simulate reviewing the pull request changes on the remote git-demo2 repo. View the Pull Request and the file contents.
Merge the pull request. Use whichever merge option you prefer:
- Create a merge commit.
- Squash and merge.
- Rebase and merge.
As the contributor:
In your local git-demo2-fork repo, checkout the main branch.
Get in sync with the original git-demo2 remote repo.
Get your git-demo2-fork repo in sync with your local repo.
Delete the patch-feature4 branch.
Wrap up
Go back to your local git-demo2 repo.
Sync with the remote.
Log all commits using the oneline and graph options.
Add tags for feature2, feature3, and feature4.
Push the tags to the remote.
Use the Git command to see all your branches. Keep only the main branch.
Repeat the whole process if necessary until you are comfortable with all the above actions.
Make sure you are familiar with the CheatSheet topics so you can quickly reference them in the future when needed.
Congratulations, you are now proficient with Git and GitHub!