Git & GitHub Basics
Eight examples to get you started with Git and GitHub - six basic and two intermediate.
Busque em todas as páginas da documentação
Eight examples to get you started with Git and GitHub - six basic and two intermediate.
git --version to check; any recent 2.x release works).Every project starts with either a new local repo or a copy of an existing one.
# Start a brand-new repo
git init my-aws-project
cd my-aws-project
# Or copy an existing one
git clone https://github.com/your-org/aws-sdk-service.gitgit init creates a .git folder that tracks history from this point forward.git clone copies the full history, not just the current files, so you can browse past commits immediately.git status right after either command to confirm you're in a clean, tracked working directory.Git splits "what changed" from "what you're about to save" - staging is that middle step.
echo "print('hello')" > app.py
git add app.py
git commit -m "Add initial script"git add moves a file's current contents into the staging area; it does not save history yet.git commit takes what's staged and creates a permanent snapshot with a message.git add . stages everything changed in the current directory; use it carefully so you don't stage files you didn't mean to commit.Before committing, confirm exactly what you're about to save.
git status
git diffgit status lists modified, staged, and untracked files in one summary.git diff shows line-by-line changes for unstaged edits; git diff --staged shows what's already staged.Branches let you work on a change without touching the shared history until it's ready.
git branch feature/add-retry-logic
git checkout feature/add-retry-logic
# Or in one step
git checkout -b feature/add-retry-logicmain, so the shared branch stays deployable.git branch alone lists your local branches; the current one is marked with *.git branch -d feature/add-retry-logic) to keep the list manageable.Local commits stay local until you push them to the remote.
git push -u origin feature/add-retry-logic-u flag links your local branch to the remote one, so future git push calls need no arguments.main.A .gitignore file tells Git which paths to never track, before you accidentally commit them.
cat > .gitignore <<'EOF'
.env
__pycache__/
*.pyc
node_modules/
.aws-sam/
EOF
git add .gitignore
git commit -m "Add .gitignore".env files often hold local AWS credentials or endpoint overrides - never commit them.__pycache__/ and *.pyc are Python bytecode caches; node_modules/ is installed JavaScript dependencies - both are regenerated, not authored..gitignore entries before the first commit that would include these paths; Git won't retroactively un-track files already committed without an extra step..env is a real incident even if you delete the file in a later commit - the old commit still has it.Related: Preventing Leaked AWS Credentials in Commits - what to do if a secret slips past
.gitignore.
Merging brings a branch's commits into another branch; conflicts happen when both branches changed the same lines.
git checkout main
git pull
git merge feature/add-retry-logic
# If a conflict appears, Git marks it in the file:
# <<<<<<< HEAD
# ...current main content...
# =======
# ...incoming feature branch content...
# >>>>>>> feature/add-retry-logic
# Edit the file to keep the right content, then:
git add app.py
git commitgit pull before merging brings main up to date so you're merging against the latest shared history.Once a repo has real history, git log and its variants help you find when and why something changed.
git log --oneline -10
git log --oneline --follow -- app.py
git blame app.pygit log --oneline gives a compact one-line-per-commit view; add -10 to limit how many you see.--follow -- app.py shows the history of a single file, including across renames.git blame shows which commit last touched each line - useful for finding who introduced a config value or a hardcoded region string.Related: Git Workflows for AWS SDK Teams - how branching and PRs fit together on a real team.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+).
Revisado por Chris St. John·Última atualização: 23 de jul. de 2026