%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
    A[Repository] --> B[file1.py]
    A --> C[file2.py]
    A --> D[file3.py]
AESB2122 - Signals and Systems with Python
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
    A[Repository] --> B[file1.py]
    A --> C[file2.py]
    A --> D[file3.py]
Local and remote in sync
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
    
    subgraph Remote Repository
        direction LR
        C[file1.py]
        D[file2.py]
    end
    subgraph Local Repository
        direction LR
        A[file1.py]
        B[file2.py]
    end
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
    A[Working Directory] --> B[Staging Area]
    B --> C[Local Repository]
    C --> D[Remote Repository]
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
    A[Working Directory] -. add .-> B[Staging Area]
    B -. commit .-> C[Local Repository]
    C -. push .-> D[Remote Repository]
git add.git commit.git push.Let’s start with a state where all changes are committed, and local and remote are in sync
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
    subgraph Remote Repo
        direction LR
        C[file1.py]
        D[file2.py]
    end
    subgraph "Local Repo (committed)"
        direction LR
        A[file1.py]
        B[file2.py]
    end
    subgraph "Working Directory (current)"
        direction LR
        W[file1.py]
        X["file2.py"]
    end
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
    subgraph Remote Repo
        direction LR
        C[file1.py]
        D["file2.py (old state)"]
    end
    subgraph "Local Repo (committed)"
        direction LR
        A[file1.py]
        B["file2.py (old state)"]
    end
    subgraph "Working Directory (current)"
        direction LR
        W[file1.py]
        X["file2.py (modified with changes)"]
    end
To add changes in file2.py to the staging area, we’ll use the command:
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
  
    subgraph Remote
        direction LR
        C[file1.py]
        D["file2.py (old state)"]
    end
    subgraph Local
        direction LR
        A[file1.py]
        B["file2.py (old state)"]
    end
    subgraph Staging
        direction LR
        S2["file2.py (modified with changes)"]
    end
    subgraph "Working Directory (current)"
        direction LR
        W[file1.py]
        X["file2.py (modified with changes)"]
    end
    X -. add .-> S2
    Staging ~~~ Local
    Local ~~~ Remote
    
Note: Git only tracks files that have been added to the repository at least once. If you create a new file, tracking starts when you git add <file>. Till then, it is untracked.
To commit changes in the staging area to the local repo, we’ll use the command:
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
  
    subgraph Remote
        direction LR
        C[file1.py]
        D["file2.py (old state)"]
    end
    subgraph Local
        direction LR
        A[file1.py]
        B["file2.py (modified with changes)"]
    end
    subgraph Staging
        direction LR
        S2["file2.py (modified with changes)"]
    end
    subgraph "Working Directory (current)"
        direction LR
        W[file1.py]
        X["file2.py (modified with changes)"]
    end
    X -. add .-> S2
    Staging -. commit .-> Local
    Local ~~~ Remote
    
To push changes from the local repo to the remote repo, we’ll use the command:
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
  
    subgraph Remote
        direction LR
        C[file1.py]
        D["file2.py (old state)"]
    end
    subgraph Local
        direction LR
        A[file1.py]
        B["file2.py (modified with changes)"]
    end
    subgraph Staging
        direction LR
        S2["file2.py (modified with changes)"]
    end
    subgraph "Working Directory (current)"
        direction LR
        W[file1.py]
        X["file2.py (modified with changes)"]
    end
    X -. add .-> S2
    Staging -. commit .-> Local
    Local -. push .-> Remote
    
The add also has an “unstage” option (git restore --staged <file>), but commit and push have no “undo” option.
Any step from commit onwards is very difficult to undo and is generally considered bad practice to do so. Hence, the term “commit”… The clue is in the name!
You can selectively add (stage) files…
… but a commit is all-or-nothing (you commit everything in the staging area).
Similarly, a push is all-or-nothing (you push all commits that haven’t been pushed yet).
git status: This command shows the current state of the working directory and the staging area.
git log: This command shows the commit history for the repository.
git diff: This command shows the differences between the working directory and the staging area, or between the staging area and the last commit.
All git commands are to be run in the terminal (command line) where you have git working.
Check if git is installed by running:
If not working, finish Exercises from the lecture last week on Version Control Systems.
<your_student_number>-sands-python (e.g., 1234567-sands-python).git init.git status to check the status of your repository.hello.py in this directory with the following content:git add hello.py.git status to see that hello.py is now staged for commit.git commit -m "initial commit").git status to confirm that there are no changes to commit.<your_student_number>-sands-python (e.g., 1234567-sands-python). Note: Create an empty repository on GitHub (without a README, .gitignore, or license).git push -u origin main.hello.py file is now available in your GitHub repository.hello.py file to change the message to:git add hello.py.git commit.git push.Voilà! Look at you go, using Git and GitHub like a pro! 🎉
signals.py in your local repository. (the same repo as the one you created during the hands-on practice)generate_sine_wave(frequency, duration, sample_rate) that generates a sine wave signal.run.py that imports the generate_sine_wave function and uses it to generate a sine wave with a frequency of 5 Hz, duration of 2 seconds, and sample rate of 100 samples per second. Have it print the first 10 samples of the generated sine wave.run.py file with an appropriate commit message.run.py to plot the generated sine wave using matplotlib instead of printing the samples.run.py with an appropriate commit message.