Git is a fabulous tool for source control management. While incredibly powerful, it can be a little daunting to learn at first. The following tutorials will help. They are organized from basic to more advanced.
- Learn Git Branching, an interactive tutorial is a very cool way to get your feet wet without having to download and install anything.
- GitFlow, a very good read on the basic workflow / process used for FlightNode development
which was used in the FlightNode project for which this tutorial was
originally written, with GitFlow-like branching structure at the core.
- In your local clones, create a new remote called *upstream**, pointing to the
git remote add upstream https://github.com/FlightNode/FlightNode.xyz
- When you want to get the latest code from the shared repository, you’ll now
be able to use
git pull upstream <somebranch>.
- 2021 update: this is still my preferred approach when working with a fork, although typically I am now working on a branch directly in the “origin” repository and don’t need to take this step.
- In your local clones, create a new remote called *upstream**, pointing to the main repository:
- Pull Request Tutorial, with many nice screenshots and some advanced functionality, such as squash, rebase, and cherry-pick.
- Pro Git, the entire book, is available online for free.
Once you’ve created your forks on GitHub, and your clones on your workstation, a typical day might look like this:
- Open Git-bash and cd to a workspace:
- Planning on working on Issue #10 today… so create a feature branch:
git checkout -b feature/10
- You don’t want to get out-of-date, or you may start running into major merge
git pull upstream develop
- Work on some code in your editor of choice.
- Stage your code:
- New file:
git add full/path/to/new/file.cs
- All existing files:
git add -u :/
- All existing files in a particular directory:
git add -u :full/path
- New file:
- Do some more work, stage some more work.
- Commit your changes:
git commit -m "10 - brief description"
(for longer description, enter a brief description on first line, then hit enter to type the longer description starting on the next line. Finish with “).
- Done for the day? Want to backup your code? Push to your fork:
git push origin feature/10
- Is the feature ready for other people to use? Then create a pull request in GitHub. In the pull request, add comments directly in the file if you want to explain something about your work. And invite others to review your code.
Many people really like SourceTree, a tool from Atlassian. I have it installed and have not yet really used it, because I’m completely comfortable with using the command line. This tool is particularly useful when you want to visualize and compare many active branches.
Visual Studio Code
Visual Studio Code’s Git support is top-notch, when you don’t feel like using the command line. You can use the tool for all of the basic operations… and probably much more beyond the basics. But personally I generally use the command line for complex things.
Perhaps the best thing about VSCode’s integration: it makes the cumbersome process of un-staging and/or reverting your code changes very easy.
In this example:
- Clicked a + icon (not shown) to move
CONTRIBUTORS.mdfrom “Changes” to “Staged Changes”.
- Clicked on the file in “Staged Changes” in order to see the diff in the text editor.
- Review the diff, confirm that it is what was expected.
- Type in a message and click the checkmark to commit the change.
- Click on
...to get the pull down menu.
- Push changes.
That menu gives many more options, for example to help you create a new branch.
For more information, see Use Git version-control tools in Visual Studio Code.
Visual Studio 2015
2021 update: in VS2019, these features are now in the “Git Changes” panel and the user interface is further improved. See Git experience in Visual Studio for more detailed information.
Visual Studio 2015’s support is actually pretty good too. I was biased against it for a long time, probably because they automatically stage files (“tracked files”) and make you purposefully unstage them (“un-tracked files”). But for most people that’s probably not a bad thing. And while I haven’t used it in VS2013 in many months, I feel like the 2015 experience is somehow a little better and a little more powerful than its predecessor.
Posted with : Tech, Software Development Life Cycle, FlightNode: Citizen Science Bird-Monitoring