tfs-demos

Git guide

These notes are not intended as a comprehensive guide to Git. Their purpose is to guide you through the main areas you should learn about, with resources provided for further exploration. The goal is for you to learn enough to use Git confidently in collaborative projects.


Introducing Git

What is it?

Why do we need it?

How do we use it?

Further Learning


Repositories

What is it?

Why do we need it?

How do we use it?

  1. Create a local repository:
    git init
    
  2. Clone a remote repository:
    git clone <repository-url>
    
  3. Add a remote (if starting locally):
    git remote add origin <repository-url>
    

Cloning vs Forking

Further Learning


.gitignore files

What is it?

Why do we need it?

How do we use it?

  1. Create a .gitignore file at the root of your project
  2. Add patterns for files or folders you want Git to ignore:
    node_modules/
    .env
    dist/
    
  3. You can use ready-made templates for common setups: GitHub gitignore templates

Commits

What is it?

Why do we need it?

How do we use it?

  1. Stage files:
    git add <filename>
    
  2. Commit changes:
    git commit -m "Add feature description"
    
  3. Push to remote:
    git push
    

Good habits

Further Learning


Branches

What is it?

Why do we need it?

How do we use it?

  1. Create a new branch:
    git checkout -b feature/new-feature
    
  2. Switch between branches:
    git checkout main
    
  3. Merge back when complete:
    git merge feature/new-feature
    

Further Learning


Merging and Rebasing

What is merging?

What is rebasing?

When to use them

Commands

git merge feature/new-feature
git rebase main

Further Learning


Undoing and Fixing Mistakes

What is it?

Why do we need it?

How do we use it?

Further Learning


Stashing Work

What is it?

Why do we need it?

How do we use it?

git stash            # Save your current changes
git switch main      # Move to another branch
git stash pop        # Restore the stashed changes

Further Learning


Remotes and Syncing

What is it?

Key commands

Why it matters

Further Learning


GitHub Flow

What is it?

How it works

  1. Create a new branch from main
  2. Commit changes regularly
  3. Push your branch to GitHub
  4. Open a pull request to merge your changes
  5. Request review and make revisions if needed
  6. Merge the pull request once approved

Further Learning


Pull Requests and Code Reviews

What is it?

Why do we use it?

How to create a good pull request

How to review code well

Further Learning


Avoiding and Resolving Conflicts

What are conflicts?

How to avoid them

How to resolve them

  1. When a conflict occurs, Git will mark the file
  2. Open it and look for conflict markers:
    <<<<<<< HEAD
    your changes
    =======
    incoming changes
    >>>>>>> feature-branch
    
  3. Edit the file to keep the correct version
  4. Mark it resolved:
    git add <filename>
    git commit
    

Further Learning


Pre-commit Hooks

What is it?

Why use them?

Example

Using the pre-commit tool:

pip install pre-commit
pre-commit install

Further Learning


GitHub Actions

What is it?

Why use them?

Example

A simple workflow file .github/workflows/test.yml:

name: Run tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test

Further Learning


Common Git Tips

Further Learning