Comprehensive list of some common Git commands and their uses

Setup & Initialization

  • git init: Initialize a new Git repository.
  • git clone [url]: Clone an existing repository.

Branching & Merging

  • git branch: List all branches in your repository.
  • git branch [branch-name]: Create a new branch.
  • git checkout [branch-name]: Switch to a branch.
  • git checkout -b [branch-name]: Create a new branch and switch to it.
  • git merge [branch-name]: Merge a branch into the active branch.
  • git branch -d [branch-name]: Delete a branch.

Staging & Commit

  • git status: Show the working directory status.
  • git add [file]: Add a file to the staging area.
  • git add .: Add all files to the staging area.
  • git commit -m "[commit message]": Commit changes with a message.
  • git commit -a: Commit all changes with a message.

Remote Repositories

  • git remote add origin [url]: Add a remote repository.
  • git remote -v: List all remote repositories.
  • git push [remote] [branch]: Push a branch to a remote repository.
  • git pull [remote]: Pull changes from a remote repository.
  • git fetch [remote]: Fetch changes from a remote repository.

Viewing History

  • git log: Show the commit history.
  • git log --oneline: Show the commit history in a single line per commit.
  • git log --graph --oneline: Show the commit history with a graph.

Undoing Changes

  • git reset [file]: Unstage a file.
  • git checkout -- [file]: Discard changes in a file.
  • git revert [commit]: Create a new commit that undoes changes in a previous commit.
  • git reset --hard [commit]: Reset your repository to a previous commit and discard all changes since.

Tagging

  • git tag [tag-name]: Create a tag.
  • git tag: List all tags.
  • git show [tag]: Show information about a tag.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了