Welcome to your first 320 assignment!! This portion will introduce you to the basic functionalities of Git and GitHub.
Here are some useful links that might be good to read through first
Before we begin though, make sure you have Git is installed on your system. If it isn't, follow the instructions below
- Windows: Download Git from git-scm.com and follow the installation instructions.
- MacOS: You can install Git using Homebrew by running
brew install git
in your terminal. - Linux: Use your package manager to install Git, e.g.,
sudo apt-get install git
for Debian/Ubuntu.
After installation, verify that Git is installed correctly by running:
git --version
This should display the version of Git installed on your system.
-
Fork this repository: Click on the "Fork" button at the top-right corner of this page. This will create a copy of the repository under your own account.
-
Clone your forked repository to your local machine:
Make sure your SSH key is set up for this step. If you don't have one set up, generate a new one with this step by step. https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
git clone [email protected]:USERNAME/REPOSITORY_NAME.git
-
Navigate to the repository
cd REPOSITORY_NAME
-
Set remote for moving changes to the remote repository
The remote serves as an alias for where your changes are uploaded pushes and pulls.
git remote set-url origin [email protected]:USERNAME/REPOSITORY_NAME.git
-
Create a new file called
answers.txt
:touch answers.txt
-
Create a new branch named
q1
and switch to it:git branch q1
-
Switch to the new branch: checkout is an old way of doing it. The more modern command you can also use it
switch
.git checkout q1
-
Add your answer to the first question in
answers.txt
: you can use any command line text editor, if you're unsure of which to use (look below)nano answers.txt
Now copy this question into the file and answer it
Q1: Why might be consider using git? Answer: [Your answer here]
-
Stage and commit your changes:
The status command gets users current changes
git status
You should see changes in
red
here, these changes areunstaged
Then we want to "add" our changed files into the Staging area. The staging area is a place where you gather all your changes to then be committed all at once later.
git add answers.txt
If we run
git status
here, we will see that the changes are nowgreen
Lets go ahead and finalize our changes. This will essentially "commit" all our changes to our LOCAL repository -- this does not effect the remote repository .
Each commit should have a quick summary of the purpose of your changes. This an be done by using the
-m
flag followed by your commit message. If you don't using it, a text editor will open for you to type in your commit message.git commit -m "answered Q1"
-
Lets Switch back to the
main
branch: -
Create a new branch named
q2
and switch to it: -
Add your answer to the second question in
answers.txt
:Q2: What field could data science be applied to? Give and Example and how it might help Answer: [Your answer here]
-
Stage and commit your changes:
-
Switch back to the
main
branch: -
Merge the
q1
branch intomain
: Merging essentially applies the changes made on a certain feature branch to the current branch its on. So in this case, we will be combiningq1
to ourmain
branchgit merge q1
-
Then Merge the
q2
branch intomain
:Here, you should have encountered a merge conflict, Git will inform you that there are conflicts in
answers.txt
. Open the file, resolve the conflicts manually using your command line text editor<<<<< HEAD
: signifies the beginning of your changes from the branch you are in=====
: This signifies the separation between the two merges. Anything above is the content from the first branch, everything below is from the content of the merging branch>>>>>
: This specified the end of the conflic
You can resolve these conflicts by removing the 3 from above^.Make sure that you have the answer and question to both problems
-
Stage the resolved file and commit the merge:
git add answers.txt git commit -m "resolved merge conflict"
Q3: What is the difference between merging and rebasing?
Answer: [Your answer here]
stage/commit when youre done
-
Create a new branch named
q3
and switch to it: -
Add your answer to the fourth question in
answers.txt
:Q4: What skills do you hope to improve during this course? Answer: [Your answer here]
-
Stage and commit your changes:
-
Switch back to the
main
branch:git checkout main
-
Rebase the
q3
branch ontomain
:rebase
essentially "replays" the changes that we made from out feature branchq3
on our main branch.git rebase q3
-
Resolve any conflicts
We didn't in this case, but if we did multiple different commits during our feature branch
q3
, we can use--continue
to move to the next commit of out feature branch.git rebase --continue
If we rebase multiple commits, but we want to discard the changes in the middle of the rebase process, we can do an
--abort
to disgard these changes.git rebase --abort
-
View Commits
git log
Notice that in the log enumerates all the commits we have added in order. When we first used the
merge
command an additional commit is incurred to contain our patches. When you userebase
for more complex changes, there is no additional commit needed here. Instead when rebasing, your git client modifies the feature commits to be merged without conflict.For more information, visit here
-
Push changes to remote repository
push
allows us to upload our changes from our local repository to our remote repository on githubgit push origin main
- Submit a link to your github for gradescope