git clone
git add *
git commit -m ".."
git push
Create local repo: git clone
Check for updates: git fetch
Integrate updates: git pull
Let's do a quick demo
# Close issue number 7
git commit -m "Added a new file. Close #7"
clone
clone
commit
commit
push
commit
push
clone
clone
commit
commit
push
commit
push
pull --rebase
# Simple case of pulling in changes (i.e., no conflict)
git pull --rebase origin master
# Push changes
git push origin master
CONFLICT!
# Put local commits on top of changes to the remote
git pull --rebase
Auto-merging your-file-name.r
CONFLICT (content): Merge conflict in your-file-name.r
# What is happening
git status
but how?
<<<<<<< HEAD
# This is the code section in your local version
# It can be multiple lines
x <- 6
======= # This is the divider between local and remote code
# This is the code section in your REMOTE version
# It can be multiple lines
x <- 7
>>>>>>> remote-branch-name-or-hash
# Put your changes on top of the remote changes
git pull --rebase
<<<<<<< HEAD # delete this non-sense!
# Keep relevant comments and code
x <- 7
# Add any/all edited files
git add .
# Continue through rebase, then push changes to GitHub
git rebase --continue
git push origin master
# When you sit down to do work, pull down changes. --rebase shouldn't matter here
git pull --rebase origin master
# Do some work. Some great work!
# Add and commit your work. Make sure messages are clear, and close issues.
git add .
git commit -m "Specific message that can close issues"
# Push your changes up to GitHub (the origin)
git push origin master
### If you get an error (b/c someone else has pushed), pull in changes w/ a rebase:
git pull --rebase origin master
# Open up files and edit them, removing >>>>, =====
# Add changes to the rebase
git add .
# Continue the rebase, no need to commit!
git rebase --continue
# After the rebase, push your changes to GitHub
git push origin master
A branch in GitHub is a way of labeling a sequence of commits. You can create labels (branches) for different commits, and effectively have different "lines" of development occurring in parallel and diverging from each other
# Create a new branch of the current commit
git branch new-idea
# Start working on the branch by checking it out
git checkout new-idea
# You can do those in one line, if you prefer
git checkout -b new-idea
# Label the current commit as a new branch super-hungry
git branch super-hungry
# Checkout (i.e., start working in) your super-hungry branch
git checkout super-hungry
# Add and commit changes as usual
git add .
git commit -m "Added super-hungry snacks"
# Checkout (i.e., switch to working in) your master branch
git checkout master
# Add and commit changes as usual
git add .
git commit -m "Changed my favorite snack"
# Merge super-hungry branch into master (current) branch
git merge super-hungry
CONFLICT!
<<<<<<< HEAD
# This is the code section in your local version
# It can be multiple lines
x <- 6
======= # This is the divider between local and remote code
# This is the code section in your REMOTE version
# It can be multiple lines
x <- 7
>>>>>>> remote-branch-name-or-hash
# Add and commit changes as usual
git add .
git commit -m "Changed my favorite snack"
# Make and checkout new branch
git checkout -b super-hungry
# Make some changes to your file, then add and commit
git add .
git commit -m "Added super-hungry fav. food"
# Switch back to master branch
git checkout master
# Make some changes, then add and commit
git add .
git commit -m "Made changes to master"
# Merge in changes from super-hungry branch
git merge super-hungry
# Resolve the conflict MANUALLY in the file, then add and commit
git add .
git commit -m "Merged in super-hungry branch"