-
Does anyone have any particularly horrible git-tastrophes that they'd like to share?
-
Any burning questions?
-
git diff
- shows all of the additions and deletions in your working directory
-
git remote -v
- check all remotes associated with local repo
-
git remote add <name(ie. origin or upstream)> <url>
- add another remote repo to your local repository
-
git stash
- saves the state of your working directory.
- It also reverts you back to a clean directory at your HEAD commit.
-
git stash pop
- gives you back changes from your last stash
-
git stash apply
- allows you to revert to a previous stash by either specicfying ie. git stash apply stash@{2}, which will take you back to the specified stash.
- Or, simply typing git stash apply will revert to your most recent stash.
-
git reset --hard
- This resets the index and the working tree. Any changes to tracked files since the last commit are discarded.
-
git reset
- This does not touch the index or working tree but resets the head to the latest commit and leaves all files unstaged.
-
Setting your git config to use a certain text editor
git config --global core.editor "sublime —wait"
It's useful to think of branches like JavaScript functions: they should be small, have descriptive names and implement a single feature. Use branches for the small features that you can implement quickly.
In pairs assign one person the role of Person 1
and the other Person 2
.
-
Person 1: Create a repo on Github with a README. Add Person 2 as a Collaborator.
-
Extra Challenge(optional): Add 2 issues to your github issues, one for Person 1, the other for Person 2.
-
Both: checkout a unique branch.
Example:
git checkout -b person1-update-readme
git checkout -b person2-update-readme
-
Both: Make changes to the same line in the README in both repos.
-
Person 1: Push your branch and open a PR.
-
Person 2: Merge the PR
- If doing the extra challenge: close the issue assigned to Person 1 via a commit message.
- halp?
- Person 2: Push your branch and open a PR.
- Notice that we can’t merge it automatically
- We need to fix it locally first
-
Person 2: checkout the master branch.
-
Person 2: Pull from master on Github.
-
Person 2: Checkout the branch you have an open PR for.
-
Person 2: Merge master into your current branch.
- This should throw an error CONFLICT (content): Merge conflict in readme.md Automatic merge failed; fix conflicts and then commit the result.
-
Person 2: Open the file it says the conflict occurs in. You can see it if you run git status
-
Person 2: You see something that looks like this:
<<<<<<< HEAD
Person 2 adds a line!
=======
Person 1 Adds a line!
>>>>>>> master
- Person 2: Update the line to look the way you want it to look
- Remove the
<<<< HEAD
,=======
, and>>>> master
lines
- Person 2: running git status tells you how to mark the conflict as resolved
- After resolving and running git status you will see a
Changes to be committed
message.
-
Person 2: Commit the resolved changes
-
Person 2: Push the changes to your branch on Github
-
Reload the pull request
- It should now be able to be merged in automatically
- You should also see the commit that merged the two changes
- If doing the extra challenge: Person 1: Merge the PR and close the issue via your commit message. halp?
- If not: Person 1: Just merge the PR