Git Basics and Practical Workflows¶
1. Installing Git¶
Download Git from the official site:
Choose the installer for your operating system, then follow the installation wizard.

2. Core Concepts¶
Git is a distributed version control system. It tracks file changes, supports collaboration, and preserves a project's history.
- Branch: an independent line of development created from the main branch or another branch.
- Commit / revision: a recorded snapshot of changes. Git lets several developers work on the same project, compare revisions, and restore an earlier state when necessary.
3. Common Git Commands¶
3.1 Initial configuration¶
After installing Git, configure your identity:
# Global user name and email
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
# Repository-local identity, when required
git config user.name "Your Name"
git config user.email "[email protected]"
# Inspect the active configuration
git config --list
3.2 Cloning a repository¶
The following example clones version v3.1.5 of the AWS IoT Device SDK for Embedded C:
# Method 1: clone the latest revision, then switch to a tag
git clone https://github.com/aws/aws-iot-device-sdk-embedded-C.git
cd aws-iot-device-sdk-embedded-C
git tag -l
git checkout v3.1.5
# Method 2: clone the target tag directly
git clone --branch v3.1.5 https://github.com/aws/aws-iot-device-sdk-embedded-C.git
3.3 Switching and creating branches¶
Use branches to isolate a change before it is merged back into the shared line of development.
# Show the current local branch
git branch
# Show remote branches
git branch -r
# Switch to an existing branch
git checkout <branch-name>
# Create and switch to a new branch
git checkout -b <new-branch-name>
3.4 Returning to an earlier revision¶
If a feature is no longer needed or a change is incorrect, Git can move the branch back to an earlier commit:
# Move back two commits
git reset --hard HEAD~2
# Move to a specific commit
git reset --hard <commit-hash>
To undo the most recent commit:
# Remove the last commit but keep changes in the working tree
git reset HEAD^
# Remove the last commit and discard the working-tree changes
git reset --soft HEAD^
# Create a new commit that reverses the previous one
git revert HEAD
Be careful with
git reset --hardand force-push operations: they can discard uncommitted work or rewrite shared history.
4. A Typical Team Workflow¶
For a team working on a shared repository, create a branch for each piece of work and merge it after review.
Step 1: Clone the repository¶
Step 2: Create a working branch¶
Choose a name that describes the work, for example feature-branch:
Step 3: Stage and commit changes¶
Step 4: Bring in the latest shared changes¶
Before publishing your work, fetch and merge the current main branch: