Github Terminal
Git is a distributed version control system that helps you track changes in your codebase, collaborate with others, and manage different versions of your project. Here's an overview of the basic Git life cycle and some commonly used commands:
1. **Initialize a Git Repository:**
- `git init`: Initializes a new Git repository in the current directory.
2. **Clone a Repository:**
- `git clone <repository_url>`: Creates a copy of a remote repository on your local machine.
3. **Working Directory:**
- Your local copy of the repository where you make changes.
4. **Staging Area (Index):**
- `git add <file>`: Adds changes in the working directory to the staging area.
- `git add .` or `git add -A`: Adds all changes to the staging area.
5. **Committing Changes:**
- `git commit -m "Commit message"`: Commits changes from the staging area to the repository.
- `git commit -a -m "Commit message"`: Commits all changes (skipping the staging area).
6. **Viewing Changes:**
- `git status`: Shows the status of changes as untracked, modified, or staged.
- `git diff`: Shows the differences between the working directory and the staging area.
- `git diff --staged` or `git diff --cached`: Shows the differences between the staging area and the last commit.
7. **Branching:**
- `git branch`: Lists all branches in the repository.
- `git branch <branch_name>`: Creates a new branch.
- `git checkout <branch_name>` or `git switch <branch_name>`: Switches to a different branch.
- `git merge <branch_name>`: Merges changes from one branch into another.
8. **Remote Repositories:**
- `git remote -v`: Shows a list of remote repositories.
- `git remote add <name> <url>`: Adds a remote repository.
- `git pull <remote> <branch>`: Fetches changes from a remote repository and merges them into the current branch.
- `git push <remote> <branch>`: Pushes changes to a remote repository.
- `git push <remote> <branch> --rebase`: Pushes changes to a remote repository when merging regarding error comes.
::: ADD Globally Username and Email :::
git --version
git config --global user.name "name here"
git config --global user.email "email id"
:::show name of email:::
git config --global user.email
9. **Tagging:**
- `git tag <tag_name>`: Creates a lightweight tag at the current commit.
- `git tag -a <tag_name> -m "Tag message"`: Creates an annotated tag with a message.
10. **Undoing Changes:**
- `git reset <file>`: Unstages changes.
- `git reset --hard <commit>`: Resets the repository to a specific commit, discarding changes.
- `git revert <commit>`: Creates a new commit that undoes changes made in a previous commit.
- `git clean -n` and `git clean -f`: Shows and removes untracked files.
These are just some of the basic Git commands. Git has a rich set of features, so you might want to explore more commands and options as you become more familiar with it.
Comments
Post a Comment