1. git init
- Initializes a new Git repository in the current directory.
2. git clone <repository_url>
- Clones an existing Git repository to your local machine.
3. git add <file_name>
- Adds a file to the staging area for the next commit.
4. git commit -m "Commit message"
- Commits the changes in the staging area to the local repository with a descriptive message.
5. git status
- Displays the status of changes (untracked, modified, staged) in the working directory.
6. git diff
- Shows the difference between the working directory and the staging area.
7. git push
- Pushes the committed changes from the local repository to a remote repository.
git push origin main
8. git pull
- Fetches changes from a remote repository and merges them into the current branch.
git pull origin main
9. git branch
- Lists all the branches in the local repository.
- This command lists all the branches in the local repository. Output might look like:
* main
development
feature/new-feature
10. git checkout <branch_name>
- Switches to the specified branch.
git checkout development
- This command switches to the
development branch.
11. git merge <branch_name>
- Merges the specified branch into the current branch.
git merge feature/new-feature
- This command merges the
feature/new-feature branch into the current branch.
12. git log
- Displays a chronological list of commits in the repository.
13. git reset
- Resets the current HEAD to a specified state (commit) while preserving changes in the working directory.
git reset HEAD~1
- This command resets the current HEAD to the previous commit (
HEAD~1), preserving changes in the working directory.
14. git stash
- Temporarily shelves changes in the working directory, allowing you to switch branches without committing.
git stash save "work in progress"
- This command temporarily shelves changes in the working directory with a message "work in progress", allowing you to switch branches without committing.
15. git revert <commit_hash>
- Reverts a commit by creating a new commit that undoes the changes made in the specified commit.
git revert abc123
- This command reverts the changes introduced by the commit with hash
abc123, creating a new commit that undoes those changes.
16. git remote -v
- Displays the URLs of the remote repositories associated with the local repository.
17. git fetch <remote_name>
- Fetches changes from a remote repository without merging them into the local branch.
18. git tag <tag_name>
- Creates a lightweight tag at the current commit.
19. git merge --abort
- Aborts the current merge operation and restores the state before the merge.
20. git cherry-pick <commit_hash>
- Applies the changes introduced by the specified commit to the current branch.