1. **Initialize a Repository**:
- `git init`: Initializes a new Git repository in the current directory.
2. **Clone an Existing Repository** (if not starting from scratch):
- `git clone <repository_url>`: Clones an existing remote Git repository to your local machine.
3. **Configure Git** (if not already configured):
- `git config --global user.name "Your Name"`: Sets your name for Git commits.
- `git config --global user.email "youremail@example.com"`: Sets your email for Git commits.
4. **Check the Status**:
- `git status`: Shows the status of your working directory, including changes not yet committed.
5. **Stage Changes**:
- `git add <file>`: Stages specific files for the next commit.
- `git add .` or `git add --all`: Stages all changes in the current directory.
6. **Commit Changes**:
- `git commit -m "Your commit message"`: Commits staged changes to the local repository.
7. **Branching**:
- `git branch`: Lists all branches in the repository.
- `git branch <branch_name>`: Creates a new branch.
- `git checkout <branch_name>`: Switches to the specified branch.
- `git checkout -b <branch_name>`: Creates and switches to a new branch in one command.
8. **Merging**:
- `git merge <branch_name>`: Merges changes from one branch into the current branch.
9. **Fetching and Pulling Changes** (from a remote repository):
- `git fetch`: Retrieves changes from a remote repository without merging.
- `git pull`: Retrieves and merges changes from a remote repository.
10. **Pushing Changes** (to a remote repository):
- `git push origin <branch_name>`: Pushes local changes to a remote repository.
11. **Viewing Commit History**:
- `git log`: Shows a detailed commit history.
- `git log --oneline`: Shows a simplified commit history.
12. **Discard Changes**:
- `git reset <file>`: Unstages changes for a specific file.
- `git reset`: Unstages all changes.
- `git checkout -- <file>`: Discards changes in a specific file.
- `git reset --hard`: Discards all changes in the working directory.
13. **Resolving Conflicts**:
- During a merge or rebase, you may encounter conflicts. Resolve them manually, then:
- `git add <file>`: Mark the resolved file as staged.
- `git rebase --continue` or `git merge --continue`: Continue the merge or rebase process.
14. **Tagging**:
- `git tag -a <tag_name> -m "Tag message"`: Create an annotated tag at the current commit.
15. **Removing and Deleting**:
- `git rm <file>`: Removes a file from the repository and stages the removal.
- `git mv <old_name> <new_name>`: Renames a file.
- `git branch -d <branch_name>`: Deletes a branch locally.
- `git push origin --delete <branch_name>`: Deletes a remote branch.
16. **Stashing Changes**:
- `git stash save "Stash message"`: Temporarily saves changes that are not ready to be committed.
17. **Pull Requests and Code Review** (GitHub/GitLab/Bitbucket):
- Create a pull request to propose changes from one branch to another.
- Review code changes and discuss them with collaborators.
- Merge the pull request when ready.
18. **Managing Remotes**:
- `git remote -v`: List remote repositories.
- `git remote add <name> <url>`: Add a remote repository.
- `git remote remove <name>`: Remove a remote repository.
- `git remote set-url <name> <new_url>`: Change the URL of a remote repository.
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......