0% found this document useful (0 votes)
3 views

Git

Uploaded by

molir52351
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Git

Uploaded by

molir52351
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Git

Here is a comprehensive list of Git commands categorized by their functionality:

Setting Up and Configuring Git

- **Initialize a repository**: `git init`


- **Clone a repository**: `git clone <repository-url>`
- **Configure user name**: `git config --global user.name "Your Name"`
- **Configure email**: `git config --global user.email "[email protected]"`
- **List configurations**: `git config --list`
- **Get help**: `git help <command>`

Basic Snapshotting

- **Check the status**: `git status`


- **Stage files for commit**: `git add <file-or-directory>`
- **Unstage files**: `git reset <file>`
- **Commit changes**: `git commit -m "Commit message"`
- **Amend last commit**: `git commit --amend`
- **View commit history**: `git log`
- **View a specific commit**: `git show <commit>`
- **Remove files**: `git rm <file>`
- **Move or rename files**: `git mv <old-filename> <new-filename>`

Branching and Merging

- **List branches**: `git branch`


- **Create a new branch**: `git branch <branch-name>`
- **Switch to a branch**: `git checkout <branch-name>`
- **Create and switch to a new branch**: `git checkout -b <branch-name>`
- **Merge a branch**: `git merge <branch-name>`
- **Delete a branch**: `git branch -d <branch-name>`
- **Force delete a branch**: `git branch -D <branch-name>`

Remote Repositories

- **Add a remote repository**: `git remote add <name> <url>`


- **List remote repositories**: `git remote -v`
- **Fetch changes from a remote repository**: `git fetch <remote>`
- **Push changes to a remote repository**: `git push <remote> <branch>`
- **Pull changes from a remote repository**: `git pull <remote> <branch>`
- **Remove a remote repository**: `git remote remove <name>`
Rewriting History

- **Revert a commit**: `git revert <commit>`


- **Reset to a specific commit**: `git reset --hard <commit>`
- **Interactive rebase**: `git rebase -i <base-commit>`

Stashing Changes

- **Stash changes**: `git stash`


- **List stashes**: `git stash list`
- **Apply stashed changes**: `git stash apply`
- **Apply and drop stashed changes**: `git stash pop`
- **Drop a stash**: `git stash drop`
- **Clear all stashes**: `git stash clear`

Viewing and Comparing

- **View changes**: `git diff`


- **View staged changes**: `git diff --staged`
- **View changes for a specific file**: `git diff <file>`
- **View differences between commits**: `git diff <commit1> <commit2>`
- **Show commit history of a file**: `git log -- <file>`

Tagging

- **Create a tag**: `git tag <tag-name>`


- **Create an annotated tag**: `git tag -a <tag-name> -m "Tag message"`
- **List tags**: `git tag`
- **Push tags**: `git push <remote> --tags`
- **Delete a tag**: `git tag -d <tag-name>`

Advanced Commands

- **Cherry-pick a commit**: `git cherry-pick <commit>`


- **Bisect to find a bug**: `git bisect start`, `git bisect good <commit>`, `git bisect bad <commit>`
- **Reflog to view history of HEAD**: `git reflog`

Collaboration

- **Create a branch from a tag**: `git checkout -b <branch-name> <tag-name>`


- **Fetch and checkout a pull request**: `git fetch origin pull/<ID>/head:<branch-name>`
- **Squash commits**: `git rebase -i <base-commit>`, then mark commits as `squash` or `fixup`
- **Resolve merge conflicts**: `git mergetool`
- **Show log of changes with differences**: `git log -p`

These commands cover a wide range of Git functionalities that you might need for version
control and collaboration.

You might also like