
This article will help you get started with Git.
Git is an extremely powerful tool. An understanding of Git will help you collaborate with product development engineers and it will help you solve some of your product security challenges.
Mastering Git leads to clearer communication and better teamwork between security and development teams. Here are three other reasons security engineers should learn Git:
Incident Response - Git's detailed history and logs can help during incident investigations.
Remediation - Git is your source of truth when verifying whether a vulnerability has been fixed.
Collaboration - Git can help with tasks where teamwork and version tracking are important. I've used it for meeting notes and weekly business review metrics.
You are in luck. Learning Git won't take a long time. In a few minutes, you can learn enough to start using Git.
Here’s how to get started:
Git uses a series of snapshots, and it operates more like a filesystem. Git records a SHA-1 checksum hash for every file or directory it tracks. This makes Git more efficient than previous version control systems.
This is important. Git tracks the state of each file. The possible states are:
Untracked - a new file that is not tracked by Git.
Modified - you have modified the file but have not committed it yet.
Staged - you have moved the file to staging. It is ready to be committed.
Committed - your change is safely stored in your local Git database.
Working - includes local copies of the files in the state they were in at the last commit.
Staging - a queue of changes that will go into your next commit.
Commit - Git has saved your file state and recorded a hash in your .git directory.
Create, change, or delete a file in your working tree. This is the filesystem directory that contains your Git repository.
Stage (or add) the changes you want to include in your next commit. You use the git add <filename> command to stage files and directories.
Create a commit with the git commit -m <commit message> command. This stores a snapshot and hash in your .git directory.
You can (optionally) use git push to push that commit to a remote repository (like GitHub).

Git Workflow
Many people gain a theoretical knowledge of Git and then stop learning. Theory can only take you so far. Let's fix that.
If you don't have Git installed, head over to the following documentation site for help:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
You should be able to open a terminal or command prompt. Type git --version. The command should return your Git version.
Next, configure the username and email for your commits. You do this by typing the following:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Next, create a directory somewhere on your filesystem. You can delete it later, so don't overthink this.
Change directories into your test directory and type git init.
Now create a simple text file in your Git repository directory.
You can check the state of your repository with the git status command
Git's return message indicates that you have an untracked file that you can add. Let's do that.
Your file is now staged. If you run git status again, Git will tell you that the file is staged for the next commit.
To commit the file, type:
Finally, check out the (very short) commit history for your repository.
Last, but not least, let's chat about branches, merges, and pull requests.
Branches are a way to separate your development work from the default (e.g. main or master) branch. It lets you do your work on a separate snapshot. You can later "merge" your changes into the default branch.
Here's what that looks like in practice. We will create a new branch in our git repository with the git branch command.
Let's view the branch we just created using the git branch command.
This created the branch named test. The git branch command shows we now have two branches: main and test. We are currently on the main branch (designated by the *).
Let's switch to the test branch with the git checkout command.
Go ahead and make some changes to your test branch and commit them.
Now, we want to merge our test branch with our default branch (main). We do that by switching back to the main branch and running the merge command.
The syntax is git merge <name of branch you want to merge>
Reference book: https://git-scm.com/docs
Pro Git book: https://git-scm.com/book/en/v2
Interactive Git branching tutorial: https://learngitbranching.js.org
