DEV Community

Cover image for Understanding The Git Workflow: Working Directory, Staging, Commit and Push.
Brian Mugo
Brian Mugo

Posted on

Understanding The Git Workflow: Working Directory, Staging, Commit and Push.

Introduction

Git is the most widely used version control system which tracks the changes to files over a period of time. This happens in the working directory which is where one makes changes to the files and you then move to the staging area where you prepare the changes before committing them.
The local repository is where your project is stored locally on your computer whereas the remote repository is where your project is hosted on the internet and allows collaboration by multiple people.

Git Workflow

The Git workflow is now the process of moving changes from the working directory to the staging area then to the local repository and finally to the remote repository.

Working Directory

This is where one creates or modifies files; for example
creating a file: touch README.md or modifying a file.
You then run git status to confirm you are in a git repository and that the README.md file now shows as an untracked file. If it says 'not a git repository' then run git init first.

Staging Area

Once you have made changes you then tell Git the changes that you want to include in the next commit: If you want to add a single file, use git add filename, for example git add README.md. To stage everything, use git add ..

Local Repository

Once satisfied with what you have staged you then go ahead and create a commit: git commit -m "Add README.md" which creates a local commit in your repo's history.

Remote Repository

Finally your local commit is ready to be sent to a remote repository such as GitHub by pushing it: git push.
There is another command git pull which brings changes from the remote repository into your local repository.

Git Workflow

Conclusion

When I tried pushing my first repo things did not run as smoothly as my explanation makes it seem. Because I was writing my Git commands the wrong way, I was not leaving spaces for instance git add. instead of git add . where they are supposed to be, other times I was forgetting the hyphens and using lowercase letters where they were supposed to be uppercase such as the example below where the first command is how I wrote it instead of writing it as the second command line.

ssh-keygen t ed25519 -c "my email address"
ssh-keygen -t ed25519 -C "my email address"
Enter fullscreen mode Exit fullscreen mode

These mistakes, though, made me understand that one has to get everything right when writing the Git commands. This is vital for the whole process of pushing from local repository to the remote repository and pulling from the remote repository to the local repository. If the commands are not written the right way, you will not be able to successfully complete the process.

Top comments (0)