Hello Friends, Welcome to my blog.
In this blog we will learn some most commonly using git commands in day to day work.
Here are some commonly used Git commands:
1. Initialization:
git init: Initialize a new Git repository in the current directory.
So, we can use this command to initialize the empty directory as a git directory, once we ran this command it will creat .git folder.
2. Cloning:
git clone <repository_url>: Clone a repository from a remote to your local machine.
For example, If you have a remote repository in github or bitbucket so you want to clone a entire source code into local you can use git clone along with repository URL as shown above.
We can find the URL in remote repository itself.
3. Tracking Changes:
git status: Check the status of your working tree.
- `git add <file>`: Add a file to the staging area.
- `git add .` or `git add --all`: Add all changes to the staging area.
- `git commit -m "Commit message"`: Commit staged changes to the repository.
4. **Branching**:
- `git branch`: List all local branches.
- `git branch <branch_name>`: Create a new branch.
- `git checkout <branch_name>`: Switch to a different branch.
- `git checkout -b <branch_name>`: Create and switch to a new branch.
5. **Merging**:
- `git merge <branch_name>`: Merge changes from `<branch_name>` into the current branch.
6. **Remote Repositories**:
- `git remote -v`: List all remote repositories.
- `git remote add <name> <url>`: Add a new remote repository.
- `git push <remote> <branch>`: Push local commits to a remote repository.
- `git pull <remote> <branch>`: Fetch and merge changes from a remote repository.
7. **Undoing Changes**:
- `git reset <file>`: Unstage changes in `<file>`, keeping modifications.
- `git reset --hard HEAD`: Reset the index and working directory to the last commit.
- `git revert <commit>`: Revert a commit by creating a new commit.
8. **Logging and History**:
- `git log`: View commit history.
- `git log --oneline`: View compact commit history.
9. **Stashing**:
- `git stash`: Stash changes in the working directory.
- `git stash list`: List all stashes.
- `git stash apply`: Apply the most recent stash.
10. **Tagging**:
- `git tag`: List all tags.
- `git tag <tag_name>`: Create a new tag.
- `git push --tags`: Push tags to a remote repository.
These commands cover a broad range of Git functionalities. Each command typically has additional options and parameters, so feel free to explore `git --help` or `git <command> --help` for more details on specific commands.
Thanks for reading š
Yours VKš