generated from USGS-R/ds-gitflows-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Welcome to the end of the hands on tutorial with Git and GitHub! You have now been exposed and practiced the basic workflow that USGS DS uses for collaborating on codebases. See the bottom of this issue for instructions about next steps.
The conceptual diagram of the workflow you just learned/used
A summary list of commands that were used.
Setting up a new project
- Fork the canonical repo to your username.
- Create a local copy of your fork - copy the SSH URL from your fork's GitHub page, then in Git Bash run
git clone [insert your fork's SSH URL]. - Add the canonical repo as a remote to your local version - copy the SSH URL from the canonical repo's GitHub page, then in Git Bash run
git remote add upstream [insert canonical repo's SSH URL]. - Verify that you are ready to go with remotes - run
git remote -vand check that your fork's URL is next tooriginand the canonical repo is listed next toupstream.
Saving a change locally
- Change the file(s).
- Inspect what changes git detects - run
git status - Stage the files that you want to include in your commit -
git add [insert file name]. Pro tip: usegit add .to stage all changed files listed withgit status. - Commit your staged changes -
git commit -m "[commit message here]"
Moving your local commits to your fork
- Run
git push origin master - Look at the "commits" page on your fork on GitHub to see your new commits.
Adding your changes to the canonical repository
- Once you have changes on your fork that make it different from the canonical repository, go to your fork's GitHub page and click "New pull request".
- In the next screen, verify that the
baserepository shows the canonical and theheadrepository shows your fork. - Click "Create pull request".
- Add a title and description. Include a peer as a reviewer and link to any related issues by adding
#[issue number]in your description. - The reviewer will merge the changes.
- Close the loop by pulling down the changes from upstream to your local repo -
git pull upstream master
Handling merge conflicts
- If you have a merge conflict after pulling down changes, look in the file(s) that have been flagged as having conflicts.
- Inspect the content between
<<<<<<< HEADand=======, which is the content that existed before the merge (likely your content). - Now inspect the content between
=======and>>>>>>> [string of letters and numbers], which is the content that is trying to be merged with what currently exists locally (likely the remote content). - Decide what of that content to keep and what to delete.
- Remove the merge conflict symbols,
<<<<<<< HEAD,=======, and>>>>>>> [string of letters and numbers]. - Save the file and then commit your merge resolution (see above for making commits). The the message "resolve merge conflict" is often used.
Feeling confident? Explore more!
There is a lot more Git that can be learned, but the above are the basics that will probably be enough for awhile. As you start to get more advanced, there may be some additional concepts/commands you should learn such as,
- Temporarily hiding changes in order to pull upstream changes to avoid conflicts (
git stash,git stash apply), - branching (
git checkout -b), and - much more!
Action: Once you are done reading this, close this issue and return to the canonical repo's main GitHub page https://github.com/USGS-R/ds-gitflows-[username].
