Created
March 5, 2013 17:12
-
-
Save mkoby/5091960 to your computer and use it in GitHub Desktop.
Version Control with Git - 04 - Remotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To set up a local remote of our current repository, we need to do a few things | |
# Here I assume the directory to the repository is ~/codecasts.tv/cctv_git (where we'll be doing the work) | |
cd ~/codecasts.tv | |
git clone --bare ~/codecasts.tv/cctv_git #This creates a new directory, ~/codecasts.tv/cctv_git.git, that acts like a remote | |
# Now we will clone the remote to our 'local' box as Harry (developer #1) | |
mkdir harry | |
cd harry | |
git clone ~/codecasts.tv/cctv_git.git | |
cd cctv_git | |
git remote -v #lists the remotes for this repository | |
#result of 'git remote -v' | |
origin ~/codecasts.tv/cctv_git.git (fetch) | |
origin ~/codecasts.tv/cctv_git.git (push) | |
#Make changes to files in repository. Now we need to push them up | |
git add -A #add all changes | |
git commit -m "Add changes" | |
git push origin master #pushes the changes in our local master branch to the master branch at the origin remote | |
# New developer joins needs to get changes | |
# this works the same as before, using the clone command passing the remotes address | |
# new developer is named Bob | |
cd ~/codecasts.tv | |
mkdir bob | |
cd bob | |
git clone ~/codecasts.tv/cctv_git.git | |
cd cctv_git | |
git log #shows the log, and should show Harry's changes | |
# Bob does some work and pushes his changes up, the same way Harry did | |
git push origin master | |
#Harry pulls the changes from the remote using the following command | |
git pull origin master # this pulls the changes from the master branch at origin to the local master branch on Harry's machine | |
# Harry could also pull the changes by using 'git fetch'. | |
# | |
# The 'fetch' command will pull down the changes from the remote but will not merge them. | |
# Think of it like this. The 'fetch' command grabs the metadata, but you do the merge yourself. | |
# Whereas with the 'pull' command, it both pulls down and attempts to merge the changes. | |
# | |
# Here's what merging using the 'fetch' command looks like: | |
git fetch origin | |
git merge origin/master | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment