Git Commands Guide

User
Git all commands and description
Assistant
Here is a comprehensive list of Git commands with their descriptions:

### **1. Configuration**
– `git config –global user.name "Your Name"` – Set the user name for commits.
– `git config –global user.email "your.email@example.com"` – Set the email for commits.
– `git config –global core.editor "vim"` – Set the default editor.
– `git config –global -l` – List all global configurations.

### **2. Basic Commands**
– `git init` – Initialize a new Git repository.
– `git clone ` – Clone a repository from a remote source.
– `git status` – Check the status of the working directory and staging area.
– `git add ` – 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 -am "commit message"` – Add and commit changes in one step.

### **3. Branching and Merging**
– `git branch` – List all branches.
– `git branch ` – Create a new branch.
– `git checkout ` – Switch to a different branch.
– `git checkout -b ` – Create and switch to a new branch.
– `git merge ` – Merge a branch into the current branch.
– `git branch -d ` – Delete a branch.
– `git branch -D ` – Force delete a branch.

### **4. Remote Repositories**
– `git remote -v` – View remote URLs.
– `git remote add origin ` – Add a remote repository.
– `git push origin ` – Push a branch to the remote repository.
– `git push -u origin ` – Push a branch and set upstream tracking.
– `git pull origin ` – Pull changes from a remote repository.
– `git fetch origin` – Fetch changes from the remote repository without merging.

### **5. Undoing Changes**
– `git reset ` – Unstage a file.
– `git reset –soft HEAD~1` – Undo the last commit but keep changes staged.
– `git reset –mixed HEAD~1` – Undo the last commit and unstage changes.
– `git reset –hard HEAD~1` – Undo the last commit and remove all changes.
– `git revert ` – Create a new commit that undoes a previous commit.

### **6. Stashing**
– `git stash` – Stash changes temporarily.
– `git stash list` – List stashed changes.
– `git stash apply` – Apply the latest stash without deleting it.
– `git stash pop` – Apply and remove the latest stash.
– `git stash drop` – Delete the latest stash.

### **7. Logs and History**
– `git log` – Show commit history.
– `git log –oneline` – Show a simplified commit history.
– `git log –graph –decorate –oneline –all` – Show a graphical representation of the commit history.
– `git reflog` – Show a log of recent actions.

### **8. Tagging**
– `git tag` – List all tags.
– `git tag ` – Create a lightweight tag.
– `git tag -a -m "Tag message"` – Create an annotated tag.
– `git push origin ` – Push a tag to the remote repository.
– `git push –tags` – Push all tags to the remote repository.
– `git tag -d ` – Delete a local tag.
– `git push origin –delete ` – Delete a remote tag.

### **9. Working with Submodules**
– `git submodule add ` – Add a submodule.
– `git submodule update –init –recursive` – Initialize and update submodules.
– `git submodule foreach git pull origin master` – Update all submodules.

### **10. Advanced Commands**
– `git cherry-pick ` – Apply a specific commit from another branch.
– `git rebase ` – Reapply commits on top of another base branch.
– `git reflog expire –expire=now –all && git gc –prune=now –aggressive` – Clean up unused Git data.
– `git bisect start` – Start a binary search to find a commit that introduced a bug.

### **11. Cleaning Up**
– `git clean -f` – Remove untracked files.
– `git clean -fd` – Remove untracked files and directories.

### **12. Temporary Work**
– `git commit –amend -m "New message"` – Modify the last commit message.
– `git blame ` – Show who last edited each line of a file.
– `git shortlog -sn` – Show commit counts per author.

These commands cover most of the essential operations in Git. Let me know if you need more details on a specific command!

Leave a Comment

Your email address will not be published. Required fields are marked *