DEV Community

Dorsila Otieno
Dorsila Otieno

Posted on

Understanding Gitworkflow

Git Workflow

Git is a local version control system that tracks code changes, while GitHub is a cloud-based platform used to host those changes and collaborate with others. Together, they form the backbone of modern software development by allowing multiple developers to work on the same codebase simultaneously without overwriting each others work

Working directory of git

This is the actual, physical folder on your computer's filesystem where you view, create, edit, and delete your project files.
It can either contain :

  • Tracked files: files that Git actively monitors and includes in version control history
  • Untracked files: are any files in your working directory that have not yet been added to your Git repository's snapshots or staging area.

Staging

Staging is the process of preparing specific file changes to be included in your next commit.

Reasons for staging

  1. Atomic Commits: It allows you to group related changes together. If you fix a bug and work on a new feature at the same time, you can stage and commit the bug fix separately from the incomplete feature.
  2. Review Mechanism: It provides a safe buffer zone to double-check exactly what lines of code are moving forward.
  3. Work Checkpointing: You can stage a file at a certain point of success, continue experimenting on that file in your working directory, and still preserve your staged checkpoint.

Staging commands

  • git add "filename" Stages a specific file.
  • git init Manages project.
  • git status To see what files are currently sitting in staging vs your working directory.
  • git diff Shows differences between your working directory and your staging area.
  • git diff --staged Shows differences between your staging area and your last commit
  • git restore --staged "filename" Removes Changes from Staging

Commit and push

To save your local changes and upload them to git you need to stage your changes, commit them locally, and push them to the server.

Commands used in commit and push

The block of code below is used in the given order to commit and push;

git add
git commit -m "commit message"
git log
git log --oneline
git branch
Enter fullscreen mode Exit fullscreen mode

The next step is to create a respiratory in your github account that is linked to your gitbash then copy the link on the SSH key. Get back to gitbash and follow the steps in the block of code below;

git remote add origin <paste>
git remote -v
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Other commands used in Git

  • cd used to change directory
  • cd .. used to get backwards with one step
  • mkdir used to make a new folder
  • ls used to list folders
  • ls -la used to list all files
  • touch used to make a new file
  • echo " heading" > README.md
  • Nano README.md used to write long texts
  • cat README.md Used to read texts in README.md

Conclusion

In conclusion, Git is the industry-standard, open-source distributed version control system (DVCS) that acts as the backbone of modern software engineering. By utilizing a unique three-stage architecture (Working Directory, Staging Area, and Local Repository), Git optimizes how changes are tracked, stored, and managed over time. It bridges the gap between individual, experimental coding and large-scale, enterprise collaboration.

Top comments (0)