Steps

  1. Run git pull in the terminal to update the local git repository with the remote git repository hosted at GitHub and update the codes in the project folder.
  2. Do some work.
  3. Suppose that some code, say main/clean_data.R, is modified by the work.
    1. If the file is not yet tracked by git, run git add main/clean_data.R in the terminal to let git track the file.
    2. If the file is already tracked by git, go to the next step.
  4. Run git commit -am "some commit message" in the terminal to commit the file changes to the local git repository. The option -a indicates to commit all changes and -m indicates to add some commit message. You should always add some commit message.
  5. Run git push in the terminal to update the remote git repository hosted at GitHub with the local git repository.
    1. If you cannot push because the remote repository is ahead of the local repository, first git pull and then git push. If git pull causes a conflict, you may have to resolve the conflict.

      1. This may be done by manually resolving the conflicting code.
      2. If a file, say fileA.txt, had a conflict and you want to overwrite the local changes with the remote changes, you can run the following command in the terminal:
      git checkout --theirs fileA.txt
      git add fileA.txt
      git commit -am "overwrite fileA.txt with theirs"
      
      1. If a file, say fileA.txt, had a conflict and you want to use the local changes, you can run the following command in the terminal:
      git checkout --ours fileA.txt
      git add fileA.txt
      git commit -am "used our fileA.txt
      

Other tasks

Making a new branch

Best practices

Troubleshooting