- 1.All software engineers use version control, and Git is the most popular version control system
- 2.Version control allows us to track which versions of our code have which features, and to write code in teams while avoiding potential conflicts.
- 3.Know how to add, and commit, files to "commits", i.e. versions of our code
- 4.Know when to commit changes during project development
All software engineers use version control to manage and review project versions and to write code in teams. Git is the most popular version control system.
Version control is not strictly necessary to create programs, but it makes software development easier by reducing the fear of breaking code. If we break code when using version control, we can compare our changes to the last working version, easily find bugs to fix, or even rolling back to the last working version if needed.
In this submodule we will learn how to create code versions, more commonly known as "commits".
We will continue to learn Git techniques as we progress through Bootcamp.
The command line is the most common and canonical way to manipulate Git. There are GUI tools, but software engineers often work with Git on remote servers that are only accessible via command line.
The following are common Git commands we will use as software engineers.
- 1.We should strive to keep commits relatively small so it is easy for our team to review the changes in each commit
- 2.We should strive to only commit code when it is in a state that others would find useful; not in a broken state or with commented-out scratch code
The following exercises should help familiarise you with Git. We use text instead of code, but the Git functionality is the same. You may wish to have 3 windows open on your screen: VS Code, the Git Commands table above, and the following instructions.
- 1.Open today's folder in terminal and create a folder with the command
cdinto the folder, and initialise it as a git repo using the command
- 3.Create a text file in the command line using
touch spring-poem.txtand open it in VS Code with
- 4.Write a poem about spring (or anything) in
spring-poem.txtand save the file
- 5.Stage and commit
git add .and
git commit -m
- 6.Edit our poem to reference leaves (or anything). Stage and commit the edits
- 7.Add a 2nd poem about winter (or anything) in a new file
- 8.Add a title to our spring poem above the poem in the file
- 9.Commit the latest changes to
spring-poem.txtin 2 commits by adding 1 of them to the staging area and committing before adding the other
git logto review commits in our repo
Intro to Git video from a prior version of Rocket's Coding Basics course