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

Git Question and Answers

Uploaded by

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

Git Question and Answers

Uploaded by

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

75) git commands and purpose?

Here are some common **Git commands** and their purposes:

1. **`git init`**:
- Initializes a new Git repository in the current directory.
```bash
git init
```

2. **`git clone <repo_url>`**:


- Creates a local copy of a remote repository.
```bash
git clone https://github.com/user/repo.git
```

3. **`git status`**:
- Shows the current state of the working directory and staging area (which files
are staged, modified, or untracked).
```bash
git status
```

4. **`git add <file>`**:


- Stages changes to a file for commit.
```bash
git add file.txt
```

5. **`git commit -m "<message>"`**:


- Records the staged changes with a message describing the changes.
```bash
git commit -m "Initial commit"
```

6. **`git push`**:
- Pushes local commits to the remote repository.
```bash
git push origin main
```

7. **`git pull`**:
- Fetches and merges changes from the remote repository into the local branch.
```bash
git pull origin main
```

8. **`git branch`**:
- Lists all local branches or creates a new branch.
```bash
git branch # List branches
git branch <new_branch> # Create a new branch
```

9. **`git checkout <branch>`**:


- Switches to a different branch.
```bash
git checkout feature-branch
```
10. **`git merge <branch>`**:
- Merges changes from the specified branch into the current branch.
```bash
git merge feature-branch
```

11. **`git log`**:


- Shows the commit history.
```bash
git log
```

12. **`git diff`**:


- Shows the differences between files or commits.
```bash
git diff
```

13. **`git remote -v`**:


- Lists the remote repositories associated with your local repository.
```bash
git remote -v
```

14. **`git reset`**:


- Unstages a file or reverts changes (use with caution).
```bash
git reset <file> # Unstage changes
git reset --hard # Discards all changes
```

These Git commands are fundamental for version control, collaboration, and managing
project code efficiently.

You might also like