Skip to content

mathiasclari/Git-Cheat-Sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Git Cheat Sheet 📜

Welcome to the world of Git, a powerful version control system that keeps your project organized and collaboration smooth. Below is a professional Git cheat sheet to help you navigate Git with ease, including the git commit --amend feature and some examples of good commit messages.

Getting Started 🚀

  1. Install Git 📦

  2. Configure Your Identity 👤

    • Set your name: git config --global user.name "Your Name"
    • Set your email: git config --global user.email "[email protected]"

Git Basics 📚

  1. Initialize a Repository 🚀

    • Create a new Git repository: git init
  2. Clone a Repository 🧬

    • Clone an existing repository: git clone <repository URL>
  3. Check Status 🧐

    • View the status of your working directory: git status
  4. Add Files

    • Stage changes for commit: git add <filename> or git add . (for all changes)
  5. Commit Changes 💬

    • Commit staged changes with a descriptive message: git commit -m "Your commit message"

    Example Commit Messages:

    • feat: Add user registration functionality
    • fix: Resolve issue with login page
    • chore: Update dependencies
    • docs: Improve API documentation
    • style: Format code according to style guide
    • refactor: Reorganize project structure
    • test: Add unit tests for authentication
  6. Amend Commits with Vim ✍️

    • Edit the last commit message and changes interactively:

      git commit --amend

      This command opens the Vim text editor, allowing you to modify the commit message. Here's how to use Vim:

      • Press i to enter insert mode. You can now make changes to the text.
      • Use the arrow keys to navigate to the part of the commit message you want to edit.
      • After making your edits, press Esc to exit insert mode.

      To save your changes:

      • Type :w and press Enter. This tells Vim to write (save) the changes.
      • To exit Vim:
        • Type :q and press Enter if you haven't made any changes you want to save.
        • Type :wq and press Enter to save and exit Vim if you've made changes.

      Remember, Vim has a learning curve, but it's a powerful text editor once you get the hang of it.

    Make sure to follow these steps to successfully save your changes and exit Vim.

Branching and Merging 🌿

  1. Create a New Branch 🌱

    • Start a new branch: git branch <branch-name>
    • Switch to a branch: git checkout <branch-name>
  2. Merge Branches 🤝

    • Merge a branch into the current branch: git merge <branch-name>
  3. Delete Branch ❌

    • Delete a branch (locally): git branch -d <branch-name>
    • Delete a branch (remotely): git push origin --delete <branch-name>

History and Revisions 🕰️

  1. View Commit History 📜

    • Review commit history: git log
  2. Time Travel ⏳

    • Check out a specific commit: git checkout <commit-SHA>

Collaboration 🤝

  1. Remote Repositories 🌐

    • Add a remote repository: git remote add origin <repository URL>
  2. Pull Requests 🙏

    • Create and review pull requests on platforms like GitHub or GitLab.
  3. Resolve Conflicts 🔥

    • Address merge conflicts collaboratively.

Correcting Mistakes 🙈

  1. Reset Commits 🔄

    • Uncommit local changes: git reset HEAD~1
  2. Revert Changes ↩️

    • Create a new commit to undo previous changes: git revert <commit-SHA>
  3. Stash Changes 📦

    • Temporarily save changes for later: git stash

Tips and Tricks 🎩

  1. Aliases 🐇

    • Set up command shortcuts: git config --global alias.<alias-name> "<git-command>"
  2. Interactive Rebase 🧩

    • Reorder, squash, and edit commits interactively: git rebase -i <base-branch>
  3. .gitignore 🙅

    • Create a .gitignore file to specify files and directories to be ignored by Git.

Stay organized, collaborate effectively, and make the most of Git's capabilities in your projects. Git is a powerful tool when used proficiently. Happy coding! 🚀👩‍💻👨‍💻

About

Star this project if you find it useful! ✨

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published