date command
This commit is contained in:
@@ -1,264 +1,215 @@
|
|||||||
# Git Commands Guide
|
# Git Commands Guide
|
||||||
|
|
||||||
## Getting Started with Git
|
## 1. Installation and Setup
|
||||||
|
|
||||||
### 1. Installing Git
|
### Install Git
|
||||||
|
Download from [git-scm.com](https://git-scm.com/).
|
||||||
Before you begin, ensure Git is installed on your machine. You can download it from [git-scm.com](https://git-scm.com/).
|
|
||||||
|
|
||||||
### 2. Check Git Installation
|
|
||||||
|
|
||||||
To verify that Git is installed, run:
|
|
||||||
|
|
||||||
|
### Verify Installation
|
||||||
```bash
|
```bash
|
||||||
git --version
|
git --version
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Configure Git User Information
|
### Configure User Info
|
||||||
|
Set your name and email for commits:
|
||||||
Set up your name and email address, which will be used for your commits:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git config --global user.name "Your Name"
|
git config --global user.name "Your Name"
|
||||||
git config --global user.email "your.email@example.com"
|
git config --global user.email "your.email@example.com"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuring Git to Use a Custom SSH Key
|
## 2. SSH Key Configuration
|
||||||
|
|
||||||
If you need to use a specific SSH key for your Git operations, you can configure Git as follows:
|
|
||||||
|
|
||||||
|
Use a custom SSH key:
|
||||||
```bash
|
```bash
|
||||||
git config --add --local core.sshCommand 'ssh -i <PATH_TO_SSH_KEY>'
|
git config --add --local core.sshCommand 'ssh -i <PATH_TO_SSH_KEY>'
|
||||||
```
|
```
|
||||||
|
|
||||||
For Clone With Custom SSH Key Use:
|
Clone with custom key:
|
||||||
```bash
|
```bash
|
||||||
git -c core.sshCommand="ssh -i <key-path>" clone host:repo
|
git -c core.sshCommand="ssh -i <key-path>" clone host:repo
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 3. Initialize Repository
|
||||||
|
|
||||||
*Replace `<PATH_TO_SSH_KEY>` with the actual path to your SSH key file.*
|
Create a new Git repo:
|
||||||
|
|
||||||
## Creating and Managing a Local Git Repository
|
|
||||||
|
|
||||||
### 1. Initialize a Git Repository
|
|
||||||
|
|
||||||
Start by creating a new Git repository in your local project directory:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git init -b main
|
git init -b main
|
||||||
```
|
```
|
||||||
|
- `-b main`: Sets default branch name to `main`.
|
||||||
|
|
||||||
*The `-b main` flag sets the default branch name to "main".*
|
## 4. Basic Workflow
|
||||||
|
|
||||||
### 2. Add Files and Commit Changes
|
|
||||||
|
|
||||||
Next, stage all your files and create your initial commit:
|
|
||||||
|
|
||||||
|
### Stage and Commit
|
||||||
|
Stage all changes:
|
||||||
```bash
|
```bash
|
||||||
git add -A
|
git add -A
|
||||||
|
```
|
||||||
|
Commit changes:
|
||||||
|
```bash
|
||||||
git commit -m "Initial Commit"
|
git commit -m "Initial Commit"
|
||||||
```
|
```
|
||||||
|
|
||||||
*The `git add -A` command stages all changes, while the `git commit` command records those changes with a descriptive message.*
|
### Connect to Remote
|
||||||
|
Link local repo to remote:
|
||||||
### 3. Connect to a Remote Repository
|
|
||||||
|
|
||||||
Now, link your local repository to a remote GitHub repository:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git remote add origin <Repo-Link>
|
git remote add origin <Repo-Link>
|
||||||
```
|
```
|
||||||
|
|
||||||
*Replace `<Repo-Link>` with the URL of your GitHub repository.*
|
### Push to Remote
|
||||||
|
|
||||||
### 4. Push Changes to GitHub
|
|
||||||
|
|
||||||
Finally, push your initial commit to the remote repository:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git push origin main
|
git push origin main
|
||||||
```
|
```
|
||||||
|
|
||||||
## Common Git Commands for Beginners
|
## 5. Repository Status and History
|
||||||
|
|
||||||
### 1. Check the Status of Your Repository
|
|
||||||
|
|
||||||
To see which changes are staged, unstaged, or untracked:
|
|
||||||
|
|
||||||
|
### Check Status
|
||||||
```bash
|
```bash
|
||||||
git status
|
git status
|
||||||
```
|
```
|
||||||
|
Shows staged, unstaged, and untracked files.
|
||||||
|
|
||||||
### 2. View Commit History
|
### View History
|
||||||
|
|
||||||
To view the commit history of your repository:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git log
|
git log
|
||||||
```
|
```
|
||||||
show diffrent on each commit
|
- `git log -p`: Shows diffs per commit.
|
||||||
```bash
|
- `git log -3`: Shows last 3 commits.
|
||||||
git log -p
|
- `git log --graph`: Shows history as a graph.
|
||||||
```
|
- `git log --oneline`: Shows compact log.
|
||||||
show last 3 commit
|
|
||||||
```bash
|
|
||||||
git log -3
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git log --graph
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git log --oneline
|
|
||||||
```
|
|
||||||
|
|
||||||
*You can press `q` to exit the log view.*
|
|
||||||
|
|
||||||
### 3. Viewing Changes
|
|
||||||
|
|
||||||
To see changes made to files before staging them:
|
|
||||||
|
|
||||||
|
### View Changes
|
||||||
```bash
|
```bash
|
||||||
git diff
|
git diff
|
||||||
```
|
```
|
||||||
|
Shows unstaged changes.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git diff --staged
|
git diff --staged
|
||||||
```
|
```
|
||||||
|
Shows staged changes.
|
||||||
|
|
||||||
### 4. Staging Individual Files
|
## 6. File Operations
|
||||||
|
|
||||||
If you want to stage specific files instead of all changes:
|
|
||||||
|
|
||||||
|
### Stage Specific Files
|
||||||
```bash
|
```bash
|
||||||
git add <filename>
|
git add <filename>
|
||||||
```
|
```
|
||||||
|
|
||||||
*Replace `<filename>` with the name of the file you wish to stage.*
|
### Unstage Files
|
||||||
|
|
||||||
### 5. Undoing Changes
|
|
||||||
|
|
||||||
To unstage a file that you added by mistake:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git reset <filename>
|
git reset <filename>
|
||||||
```
|
```
|
||||||
|
|
||||||
To discard changes in a file and revert it to the last committed state:
|
### Discard Changes
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git checkout -- <filename>
|
git checkout -- <filename>
|
||||||
```
|
```
|
||||||
|
Reverts file to last committed state.
|
||||||
|
|
||||||
### 6. Cloning a Repository
|
### Rename File
|
||||||
|
|
||||||
If you want to create a copy of an existing remote repository:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone <Repo-Link>
|
git mv <old-name> <new-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
*Replace `<Repo-Link>` with the URL of the repository you want to clone.*
|
### Remove File
|
||||||
|
```bash
|
||||||
|
git rm <filename>
|
||||||
|
```
|
||||||
|
|
||||||
### 7. Creating a New Branch
|
## 7. Branch Management
|
||||||
|
|
||||||
To create a new branch for development:
|
|
||||||
|
|
||||||
|
### Create and Switch to Branch
|
||||||
```bash
|
```bash
|
||||||
git checkout -b <branch-name>
|
git checkout -b <branch-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
*Replace `<branch-name>` with your desired branch name.*
|
### List Branches
|
||||||
|
```bash
|
||||||
|
git branch
|
||||||
|
```
|
||||||
|
List with details:
|
||||||
|
```bash
|
||||||
|
git branch -v
|
||||||
|
```
|
||||||
|
|
||||||
### 8. Merging Branches
|
### Delete Branch
|
||||||
|
```bash
|
||||||
|
git branch -d <branch-name>
|
||||||
|
```
|
||||||
|
|
||||||
To merge changes from another branch into your current branch:
|
### Switch Branch
|
||||||
|
```bash
|
||||||
|
git checkout <branch-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 8. Merging
|
||||||
|
|
||||||
|
### Merge Branch
|
||||||
```bash
|
```bash
|
||||||
git merge <branch-name>
|
git merge <branch-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
rename file
|
**Merge Types:**
|
||||||
|
- **Fast-forward:** No conflicts; branch is ahead of target.
|
||||||
|
- **Three-way:** Conflicts possible; creates new merge commit.
|
||||||
|
|
||||||
|
## 9. Remote Operations
|
||||||
|
|
||||||
|
### List Remotes
|
||||||
```bash
|
```bash
|
||||||
git mv
|
git remote
|
||||||
```
|
```
|
||||||
|
|
||||||
remove file
|
### Show Remote Info
|
||||||
```bash
|
```bash
|
||||||
git rm
|
git remote -v
|
||||||
|
```
|
||||||
|
```bash
|
||||||
|
git remote show origin
|
||||||
```
|
```
|
||||||
|
|
||||||
change default editor
|
### Fetch Changes
|
||||||
```bash
|
```bash
|
||||||
git config --global code.editor "vim"
|
git fetch
|
||||||
```
|
```
|
||||||
|
Get updates without merging.
|
||||||
|
|
||||||
edit last commit message
|
```bash
|
||||||
|
git fetch --all
|
||||||
|
```
|
||||||
|
Fetch from all remotes.
|
||||||
|
|
||||||
|
## 10. Commit Management
|
||||||
|
|
||||||
|
### Edit Last Commit Message
|
||||||
```bash
|
```bash
|
||||||
git commit --amend
|
git commit --amend
|
||||||
```
|
```
|
||||||
|
|
||||||
show changes in commit
|
### Show Commit Changes
|
||||||
```bash
|
```bash
|
||||||
git show <commit-id>
|
git show <commit-id>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Revert Commit
|
||||||
```bash
|
```bash
|
||||||
git revert HEAD
|
git revert HEAD
|
||||||
```
|
```
|
||||||
|
Revert last commit.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git revert <commit-id>
|
git revert <commit-id>
|
||||||
```
|
```
|
||||||
show all branches
|
Revert specific commit.
|
||||||
|
|
||||||
|
## 11. Miscellaneous
|
||||||
|
|
||||||
|
### Change Default Editor
|
||||||
```bash
|
```bash
|
||||||
git branch
|
git config --global core.editor "vim"
|
||||||
```
|
|
||||||
show all branches but with datails
|
|
||||||
```bash
|
|
||||||
git branch -v
|
|
||||||
```
|
|
||||||
delete target branch
|
|
||||||
```bash
|
|
||||||
git branch -d <branch-name>
|
|
||||||
```
|
|
||||||
swith on target branch
|
|
||||||
```bash
|
|
||||||
git checkout <branch-name>
|
|
||||||
```
|
|
||||||
create branch and switch on it
|
|
||||||
```bash
|
|
||||||
git checkout -b <branch-name>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Clone Repository
|
||||||
```bash
|
```bash
|
||||||
git merge <target-branch>
|
git clone <Repo-Link>
|
||||||
```
|
|
||||||
on merge with have 2 method:
|
|
||||||
|
|
||||||
fast forward: if we are on latest on master and create branch and set some change and merge it ( master not changed ) commit on out branch fast come on head master
|
|
||||||
|
|
||||||
Three-way: if we are on latest on master and create branch and set some change and merge it but this time our master got some change if our brnach dont have conflict with master its merge but with new commit
|
|
||||||
|
|
||||||
show remotes (just name)
|
|
||||||
```bash
|
|
||||||
git remote
|
|
||||||
```
|
|
||||||
show remotes with full information
|
|
||||||
```bash
|
|
||||||
git remote -v
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git remote show origin
|
|
||||||
```
|
|
||||||
get changes from default remote ( just get what file changed not applyed)
|
|
||||||
```bash
|
|
||||||
git fetch
|
|
||||||
```
|
|
||||||
get changes from all remote ( just get what file changed not applyed)
|
|
||||||
```bash
|
|
||||||
git fetch --all
|
|
||||||
```
|
```
|
||||||
|
|||||||
4
Linux/Basic Administration/31-date.md
Normal file
4
Linux/Basic Administration/31-date.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
create epoch time
|
||||||
|
```bash
|
||||||
|
date -d "2026-01-13 14:31:26" +%s%3N
|
||||||
|
`````
|
||||||
Reference in New Issue
Block a user