0% found this document useful (0 votes)
2 views4 pages

Git Commands

The document provides a comprehensive guide to Git commands, covering configuration, repository setup, basic commands, branching, viewing changes, remote repositories, stashing, tagging, undoing changes, advanced commands, cleaning up, and help. Each section includes specific commands and their descriptions for effective version control and collaboration. This serves as a quick reference for users to manage their Git repositories efficiently.

Uploaded by

Akanksha Chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Git Commands

The document provides a comprehensive guide to Git commands, covering configuration, repository setup, basic commands, branching, viewing changes, remote repositories, stashing, tagging, undoing changes, advanced commands, cleaning up, and help. Each section includes specific commands and their descriptions for effective version control and collaboration. This serves as a quick reference for users to manage their Git repositories efficiently.

Uploaded by

Akanksha Chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Git commands

1. Configuration
 git config --global user.name "Your Name"
Set your name in Git configuration.
 git config --global user.email "your.email@example.com"
Set your email in Git configuration.
 git config --list
View all configuration settings.
 git config --global core.editor "code --wait"
Set a default text editor (e.g., VS Code).

2. Repository Setup
 git init
Initialize a new Git repository.
 git clone <repository_url>
Clone an existing repository.

3. Basic Commands
 git add <file>
Stage a specific file for commit.
 git add .
Stage all changes in the current directory.
 git commit -m "Commit message"
Commit staged changes with a message.
 git commit -a -m "Commit message"
Stage and commit all tracked files in one step.

4. Branching
 git branch
List all branches in the repository.
 git branch <branch_name>
Create a new branch.
 git checkout <branch_name>
Switch to a specific branch.
 git switch <branch_name>
Alternate way to switch branches.
 git branch -d <branch_name>
Delete a branch.
 git merge <branch_name>
Merge a branch into the current branch.

5. Viewing Changes
 git status
View the status of your working directory.
 git diff
Show differences in unstaged changes.
 git diff --staged
Show differences in staged changes.
 git log
View the commit history.
 git log --oneline
View a concise commit history.

6. Remote Repositories
 git remote -v
View remote repositories.
 git remote add <name> <url>
Add a new remote repository.
 git push <remote_name> <branch_name>
Push changes to a remote repository.
 git pull <remote_name> <branch_name>
Pull changes from a remote repository.
 git fetch <remote_name>
Fetch changes from a remote repository.

7. Stashing
 git stash
Save changes temporarily without committing.
 git stash list
View all stashed changes.
 git stash apply
Reapply stashed changes.
 git stash drop
Remove a specific stash.

8. Tagging
 git tag
List all tags in the repository.
 git tag <tag_name>
Create a new tag.
 git tag -a <tag_name> -m "Message"
Create an annotated tag.
 git push origin <tag_name>
Push a specific tag to a remote repository.

9. Undo Changes
 git checkout -- <file>
Discard changes in a file.
 git reset <file>
Unstage a file without discarding changes.
 git reset --soft HEAD~1
Undo the last commit but keep changes staged.
 git reset --hard HEAD~1
Undo the last commit and discard all changes.

10. Advanced Commands


 git rebase <branch_name>
Reapply commits from one branch onto another.
 git cherry-pick <commit_hash>
Apply a specific commit from another branch.
 git blame <file>
Show who modified each line in a file.
 git bisect
Perform binary search to find a bug.
 git submodule add <repository_url>
Add a submodule to your repository.

11. Cleaning Up
 git clean -f
Remove untracked files.
 git clean -fd
Remove untracked files and directories.

12. Help
 git help
Get help for Git commands.
 git <command> --help
Get help for a specific command.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy