History and Logs

To understand the fabric of your project’s history, git log is your looking glass. This powerful command reveals the chronological order of commits, helping you trace the evolution of your project.

Viewing Changes

git log --pretty=format:"%h - %an, %ar : %s"

This spell lets you see each commit’s hash, author, time, and message in a concise format, providing a quick overview of project changes.

Collaborative Enchantments

Branches known as the master or main branch.

The Branching Strategy

A common strategy in collaborative projects is the feature branch workflow:

  1. Creating a New Branch: For each new feature or bug fix.
    git checkout -b feature/your-feature-name
  2. Merging: Once the work is complete and tested, merge it back into the main branch.
    git checkout main
    git merge feature/your-feature-name

Merging, Pushing, and Pulling

Pushing

Once your feature is polished and ready, push it to the remote repository :

git push origin feature/your-feature-name

Merging

Before merging, ensure your branch is up to date with the main branch to avoid conflicts :

git fetch origin
git rebase origin/main

Pulling Changes

Keep your local repository updated with changes from your team :

git pull origin main

Initiation vs. Cloning

  • git init: Conjures a new Git repository from thin air, ideal for starting fresh spells.
  • git clone: Duplicates an existing repository, including all its history and branches, perfect for joining ongoing projects.

Git Good Practices

Here are some practices to ensure your messages stand the test of time :

  • Be Concise and Descriptive: Your first line should be a summary of the commit, followed by a detailed description if necessary.
  • Use the Imperative Mood: Write commands, not descriptions. For example, "Fix bug" or "Add feature", as if you’re instructing the code to change.
  • Commit Logical Units: Each commit should represent a single logical change. This practice makes it easier to understand and revert changes if needed.

GitKraken

For those who prefer a more visual approach, GitKraken is a potent GUI that simplifies complex Git commands into drag-and-drop actions. It’s particularly useful for visualizing branch structures and merging.

Conclusion

Mastering these advanced Git practices will not only make your work more effective but also foster a harmonious environment for collaboration within your team.