Project

General

Profile

Revision Control - Create Working Copy

To work on a project you need to create a "working" branch to edit and make your changes so other users are not affected.

Creating A Branch

First you need to create the branch both locally and on the server

From Within RStudio

  1. Open the project in RStudio
    • Make sure the Git tab shows in upper right
       
  2. Pull (get the latest version) of the code
    • Goto the Git tab
    • Click the down arrow (pull)
       
  3. Create the branch - locally and remotely
    • Click the gear - shell command in the git tab and it opens a command line window
      At command line type the commands:
       
      1. create a new local branch (use your userID)
        % git branch userID-working
         
      2. push the branch so it's visible on the server
        % git push origin userID-working
         
      3. Switch to using the branch
        % git checkout --track -b userID-working origin/userID-working

From Command Line

From the top level directory in the project type these commands at the command line.

  1. Create a remote branch (use your userID)
    % git push origin origin:refs/heads/userID-working
     
  2. Sync the remote and local repository
    % git fetch
     
  3. Switch to using the branch the first time
    % git checkout --track -b userID-working origin/userID-working
     

Switching to An Existing Local Branch

You can switch from the branch your working on to the master branch or another user's branch. If working on another team member's branch make sure they have push'ed their branch to the server so it is up to date.

Using RStudio

Note: Branches in RStudio will be listed two ways. If the branch name starts with origin/name it is a remote branch on the server only. You need to use the directions for Switching to a Existing Remote Branch. If the name is shown without origin - use these directions.

  1. Open the project in RStudio
    • Make sure the Git tab shows in upper right
       
  2. Pull (get the latest version) of the code
    • Goto the Git tab
    • Click the down arrow (pull)
       
  3. Switch to The Branch
    • Select the Branch with the small menu in the upper right of the Git Tab
      Note: If you get a message about "You are in 'detached HEAD' state" you need to follow the directions for switching to an Existing Remote Branch

Using Command Line

  1. List the local branches
    % git branch --list
     
  2. Switch to using a branch
    % git checkout branch
     
  3. Make sure branch is up to date
    % git pull

Switching to A Existing Remote Branch

If the branch exists on the server but not locally you need to make a local copy. Once you have a local copy it will be updated whenever you do a push or a pull. After you grab the branch from the server the first time you can use the directions for switching to a existing local branch.

Using RStudio

  1. Open the project in RStudio
    • Make sure the Git tab shows in upper right
       
  2. Pull (get the latest version) of the code
    • Goto the Git tab
    • Click the down arrow (pull)
       
  3. Create a local copy of branch
    • Click the gear - shell command in the git tab and it opens a command line window
      At command line type the commands:
       
      1. Switch to using the branch
        % git checkout --track -b userID-working origin/userID-working

Using Command Line

  1. List the remote branches - the branch name is only the part after the remotes/origin
    % git branch --remote
     
  2. Switch to using the branch, setup the branch to track the server branch
    % git checkout --track -b userID-working origin/userID-working
     
  3. Make sure branch is up to date
    % git pull