Making Local Changes
In this step, you will make changes to your local repository that haven't been pushed to the remote repository, creating the "ahead of origin" scenario.
Understanding Local and Remote Repositories
Git operates with a distributed model where each developer has a complete copy of the repository on their local machine. Changes made locally need to be explicitly synchronized with the remote repository.
Let's start by navigating to our project directory:
cd ~/project/git-ahead-demo
Now, let's check the current status of our repository:
git status
You should see output similar to this:
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
This means your local repository is currently synchronized with the remote repository.
Creating a New File
Let's create a new file in our repository:
echo "This is a new file for our project." > new_file.txt
After creating the file, we need to add it to Git's staging area:
git add new_file.txt
Now, let's commit this file to our local repository:
git commit -m "Add new_file.txt"
You should see output confirming your commit:
[master 1a2b3c4] Add new_file.txt
1 file changed, 1 insertion(+)
create mode 100644 new_file.txt
Checking Branch Status
Now that we've made a local commit, let's check the status of our repository again:
git status
This time, you should see:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
This message indicates that your local branch has one commit that hasn't been pushed to the remote repository yet. This is exactly the situation we wanted to create - your branch is now "ahead of origin."