Git v-2.43.0 Fundamental 2024 

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/6f6b281e-3a2a-dd1a-410b-b01ed02742a1.png)


# 1-Installing Git
**Please download according to your operating system from the following link.**

https://git-scm.com/downloads

### How to Confirm Installation
```terminal:terminal
    git --version
    git version 2.43.0.windows.1    
```

# 2-Git Configuration
## user.name & user.email
**Git configuration settings with the git config command. One of the first things you did was set up your name and email address:**

```terminal:terminal
    git config --global user.name "Your Name"
    git config --global user.email "Your Email"
```

## core.editor
```terminal:terminal
    git config --global core.editor "code --wait"
```

**This command is a Git configuration that specifies the text editor to be used for commit messages and commits. Specifically, it sets up Visual Studio Code as the editor for editing commit messages. The command is: git config --global core.editor "code --wait". This means that when Git initiates the editing of a commit message, Visual Studio Code will be launched, and the commit process will continue once the commit message has been completed.**

```terminal:terminal
    git config --global -e
```

**The command git config --global -e is used to edit Git's global settings in an editor. When this command is executed, the specified editor opens, displaying the global Git configuration as text. Users can then edit this text to modify the settings. After editing is complete, saving and closing the editor applies the changes.**

## core.autocrlf
```terminal:terminal
    git config --global core.autocrlf true
```


**The command git config --global core.autocrlf true is used to modify Git settings and enable automatic conversion of line endings. This setting is primarily employed to address differences in line endings between Windows and Unix-based systems.**

**Specifically, when this setting is set to true, Git automatically converts the line endings of text files. This ensures that in a Windows environment, CRLF (Carriage Return Line Feed) is handled appropriately, while in Unix-based environments, LF (Line Feed) is used.**

# 3-Getting a Git Repository
## Initializing a Repository in an Existing Directory
```terminal:terminal
    git init .
    Initialized empty Git repository in C:/Users/hanam/Desktop/sample-folder/.git/
```

# 4-workflow
![2024-01-01_11h20_43.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/f360fc90-455d-284c-7954-972ccbb1d8b1.gif)

## create file
```terminal:terminal
    echo hello > file1.txt
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/6f070da4-1beb-6863-af88-d12ac7d4b21c.png)

## git status

```terminal:terminal
    git status

    On branch main

    No commits yet

    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            file1.txt

    nothing added to commit but untracked files present (use "git add" to track)
```
## git add .
```terminal:terminal
    git add .
```

## git status
```terminal:terminal
    git status

    On branch main

    No commits yet

    Changes to be committed:
      (use "git rm --cached <file>..." to unstage)
            new file:   file1.txt
    
```
## git commit -m "commit message"
```terminal:terminal
    git commit -m "initial commit"

    [main (root-commit) 0318ec2] initial commit
     1 file changed, 1 insertion(+)
     create mode 100644 file1.txt
```
```terminal:terminal
    git status

    On branch main
    nothing to commit, working tree clean
```
## git log --oneline --all --graph
```terminal:terminal
    got log --oneline --all --graph
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/c51cd102-f19d-dadb-7179-5b53401d962c.png)

# 5-Removing files

## create a new file
```terminal:terminal
    echo hello > files.txt
    git add .
    git commit-m "create a new file"
```

```terminal:terminal
    git ls-files
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/68a2bc42-8d06-b6b3-9bab-953fe8820ba1.png)


**git ls-files displays a list of tracked files in the specified Git repository. This includes files not only in the working directory but also those in the staging area (index) and files included in the committed history.**

## remove a file2.txt
```terminal:terminal
    rm file2.txt
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/d9f2ad04-d985-90f9-4b1b-49798298169c.png)

**It is tracked in the staging area.**

## git add file2.txt

```terminal:terminal
    git add file2.txt
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/497bd0c9-8e61-4823-b293-f8243de7a0ec.png)


I was able to remove it from the staging area.

## git rm file2.txt
```terminal:terminal
   git rm file2.txt 
```

**git rm file2.txt is a command in Git that removes the file file2.txt from the Git repository and simultaneously stages this deletion in the staging area (Index).**

# 6-Rename files

## mv file1.txt main.js
```terminal:terminal
    mv file1.txt main.js
    git add file1.txt
    git add main.js
    git status
```

## git mv "file1.txt" "main.js"
```terminal:terminal
    git mv "file1.txt" "main.js"
    git status
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/654025/faa76200-0aed-7560-7f7f-a42502ae7035.png)

# 7-Ignoring file

```terminal:terminal
    mkdir logs
    echo hello > logs/dev.log
    echo logs/ > .gitignore
```

```terminal:terminal
    mkdir bin
    git add .
    git rm --cached bin/
    fatal: not removing 'bin/' recursively without -r
    git rm --cached -r bin/
    git ls-files
    git commit -m "Remove the bin directory that was accidentally committed."
```