Home > Web Front-end > JS Tutorial > Useful GIT Commands and Aliases

Useful GIT Commands and Aliases

Lisa Kudrow
Release: 2025-02-23 10:31:15
Original
862 people have browsed it

This document provides a concise guide to useful Git commands and aliases, enhanced with visual aids. Let's streamline the content for improved readability and SEO.

Essential Git Commands & Aliases: A Quick Reference

This guide covers frequently used Git commands and helpful aliases to boost your workflow. If you have additional commands to share, please comment below!

Git Bash: Your Command-Line Interface

Git Bash, a command-line tool for Windows, provides a powerful interface for Git operations. (For more details, see the msysgit project website).

Useful Git Commands:

  • View all branches:

    git branch --all
    Copy after login

    Useful GIT Commands and Aliases

  • Launch Gitk (GUI): Visualize your repository's history and changes.

    gitk
    Copy after login

    Useful GIT Commands and Aliases

  • Add & Commit changes: -a stages all changes, -m adds a commit message.

    git commit -a -m "Your commit message"
    Copy after login
  • Search repository content: Find "CSS" in all .js files, for example.

    git grep "css" -- *.js
    Copy after login
  • Create a zipped backup: Creates a zip archive of the master branch (replace master with your branch name).

    git archive --format=zip master^ > backup-$(date +%d-%m-%Y).zip
    ```  *(Improved date formatting)*
    Copy after login
  • View local Git configuration:

    cat .git/config
    Copy after login

Git Aliases: Save Time & Effort

Git aliases significantly shorten frequently used commands. (See the official Git documentation for more details on alias configuration).

  • Pretty Git Log: Displays a visually appealing log history.

    git config --global alias.history "log --abbrev-commit --pretty=oneline --graph --decorate"
    # Usage: git history
    Copy after login

    Useful GIT Commands and Aliases

  • Show Last Commit:

    git config --global alias.last "log -1 HEAD"
    # Usage: git last
    Copy after login
  • Reset to Last Commit: Use with caution!

    git config --global alias.resetlast "reset --hard HEAD"
    # Usage: git resetlast
    Copy after login

Frequently Asked Questions (FAQs)

  • Purpose of Git Commands: Git commands manage and track changes in your codebase, enabling collaboration and version control.

  • Creating Git Aliases: Use git config --global alias.<alias_name> "<command>"</command></alias_name> to define a shortcut. For example: git config --global alias.co checkout

  • Understanding Gitk: Gitk provides a visual interface to explore your repository's history.

  • git fetch vs. git pull: fetch downloads changes; pull downloads and merges them.

  • Undoing a Commit: Use git revert <commit_hash></commit_hash> to create a new commit that reverses changes. git reset can also be used but is more destructive.

  • Viewing Repository History: Use git log to see commit history.

  • Resolving Merge Conflicts: Manually edit conflicted files, choose the correct changes, and commit the resolution. Tools like git mergetool can assist.

  • Cloning a Repository: Use git clone <repository_url></repository_url>.

  • Switching Branches: Use git checkout <branch_name></branch_name>.

  • Deleting a Branch: Use git branch -d <branch_name></branch_name> (ensure you're not on the branch you're deleting).

This revised version is more concise, uses stronger headings, and improves the overall presentation. The FAQ section provides clear and concise answers. The date formatting in the backup command is also enhanced for better functionality.

The above is the detailed content of Useful GIT Commands and Aliases. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template