A repository to use to get familiar with Git and GitHub.
Lecture material to support this unit.
Local/Origin/Upstream Workflow
Note: that GitHub generally guides you through the user interface using big green buttons
.
Note: I don't use --no-ff
with upstream/master below to simplifiy the history. I recommend that with GitHub, you don't use --no-ff
in this instance. If you merge a local branch to master, I would use --no-ff
Complete the following online exercise: https://try.github.io/levels/1/challenges/1
-
Log into GitHub.
-
Fork the
chaddcw/FirstGitPractice
repository.chaddcw/FirstGitPractice
is theupstream
repository. The forked copyUSERNAME/FirstGitPractice
will be theorigin
repository. -
In your forked copy, make a branch
PUNETID_FirstBranch
-
On the branch
PUNETID_FirstBranch
, use the online file editor in your web browser to edit dataFile.md. This is a file of favorite movies and/or songs. Make sure you provide a good commit message and look at the GitHub flavored markdown and Markdown Basics.
- Commit directly to
PUNETID_FirstBranch
branch.
- Go back to the forked repository. Issue a pull request back to the
upstream
repository.
- The New Pull Request button on the top left then...
- Big green button to Create pull request then...
- Add a short comment. Then press the green Create pull request button.
- DONE!
-
Review at least one other student’s pull request to indicate if that student followed directions correctly. Do this by navigating back to [chaddcw/FirstGitPractice] (https://github.com/chaddcw/FirstGitPractice) and looking through the Pull Requests (top left). Write a comment and if the student's pull request contains an error, Request Changes, if the student's pull request is correct, Approve.
-
Wait for a few minutes for your pull request to get accepted back to the upstream repository and for everyone to catch up.
-
Stop.
- Log into GitHub
- Open a terminal
- Make sure git is installed.
- Generate SSH keys to use with GitHub.
* Step 1: [Generate Keys] (https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux)
* Step 2: [Add key to GitHub] (https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-linux)
* This is a per-machine operation or you need to copy around your SSH keys (
~/.ssh/id_rsa
) to each machine you use! * [Test your SSH keys] (https://help.github.com/articles/testing-your-ssh-connection/#platform-linux). If you receive an error message let the instructor know. - Stop.
-
Do not copy and paste these commands. The " and " do not copy well.
-
In the following commands, anything past a
#
is a comment for your understanding. -
git clone [email protected]:USERNAME/FirstGitPractice.git # clone the repository to your local machine
-
cd FirstGitPractice
-
git branch # you must be on master
-
ls -al
- see the files in this directory -
cat dataFile.md
- list the contents of the file dataFile.md -
git remote add upstream [email protected]:chaddcw/FirstGitPractice.git # connect your local repos to the shared repos
-
git remote -v
-
git fetch upstream # get changes from upstream
-
git merge upstream/master # merge changes from upstream to local master
-
ls -al
-
cat dataFile.md
-
git push origin master # push changes from upstream to origin
-
Check GitHub to make sure
USERNAME/FirstGitPractice
has updated correctly.
NOTE: Step 9 and 10 could be replaced with the single step:
git pull upstream master
Why would I want to branch? A branch creates an editable copy of the repository so you can make commits without necessarily putting the commits into the main line of development. This is good for adding a feature, a bug fix, or some other set of commits that make end up as a pull request back to another Git repository.
The last reason, for a pull request, is especially important. If you make a pull request and the target of the pull request asks you to modify the pull request in any way, you can just make changes on that branch and the pull request is altered. Once the pull request is accepted, or the changes from the branch are merged back into main, the branch can be deleted (but this is not required).
- Make sure you are up-to-date.
-
git fetch upstream # get commits from the group repository
-
git merge upstream/master # merge those commits to your local repository
-
Resolve conflict if necessary
-
edit file, remove >>> ==== <<< lines
-
git add ...
-
git commit -m "message" # commit to your local repos
-
-
git push origin master # push to USERNAME/FirstGitPractice on GitHub
-
git branch AddAuthors_PUNetID # add a branch locally
-
git checkout AddAuthors_PUNetID
-
geany -i dataFile.md & #
Use Geany to edit dataFile.md and add your favorite author to the end of the file -
git add dataFile.md
-
git commit -m “added an Author” # commit to your local repos
You can customize the commit message in this step -
git push origin AddAuthors_PUNetID
Push the commits from AddAuthors branch toorigin
. This creates the branchAddAuthors_PUNetID
onUSERNAME/FirstGitPractice
on GitHub. -
Alternate to the above command is
git push -u origin AddAuthors_PUNetID
which sets the local branch to track the remote branch. -
Generate a pull request to chaddcw/FirstGitPractice from your web browser if one is not automatically generated. Make sure you are looking at branch
AddAuthors_PUNetID
in your web browser. -
Go look at your pull request on the AddAuthors_PUNetID branch in [chaddcw/FirstGitPractice] (https://github.com/chaddcw/FirstGitPractice).
-
Now I want you to change the Author's name to either ALL CAPS or all lowercase letters. Use Geany to do this locally.
-
git add dataFile.md
-
git commit -m “added an Author ALL CAPS” # commit locally
-
git push origin AddAuthors_PUNetID # push new commits on this branch to USERNAME/GitFirstPractice on GitHub
-
Go look at your pull request on [chaddcw/FirstGitPractice] (https://github.com/chaddcw/FirstGitPractice). Does it reflect the new commits?
-
Wait for the pull request to get accepted.
-
git checkout master # switch back to the master branch locally
You may see the following error. That is acceptable.
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
-
cat dataFile.md
-
git fetch upstream master # Get changes from the group repository
-
git merge upstream/master # merge changes form the group repository to master in the local repos
-
cat dataFile.md
-
git branch -d AddAuthors_PUNetID
-
git push origin master # push the newly received changes from the group repos to USERNAME/FirstGitPractice on GitHub
-
Optionally delete the
AddAuthors_PUNetID
branch on USER/FirstGitPractice on GitHub.
[Fork A Repo] (https://help.github.com/articles/fork-a-repo)
origin
: [email protected]:USERNAME/FirstGitPractice.git - the address of your GitHub repository
upstream
: [email protected]:chaddcw/FirstGitPractice.git - the address of the original GitHub repository
master
: the master branch in the local repository