LoginSignup
0
0

Git v-2.43.0 Fundamental 2024

Posted at

image.png

1-Installing Git

Please download according to your operating system from the following link.

How to Confirm Installation

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
    git config --global user.name "Your Name"
    git config --global user.email "Your Email"

core.editor

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
    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
    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
    git init .
    Initialized empty Git repository in C:/Users/hanam/Desktop/sample-folder/.git/

4-workflow

2024-01-01_11h20_43.gif

create file

terminal
    echo hello > file1.txt

image.png

git status

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
    git add .

git status

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
    git commit -m "initial commit"

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

    On branch main
    nothing to commit, working tree clean

git log --oneline --all --graph

terminal
    got log --oneline --all --graph

image.png

5-Removing files

create a new file

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

image.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
    rm file2.txt

image.png

It is tracked in the staging area.

git add file2.txt

terminal
    git add file2.txt

image.png

I was able to remove it from the staging area.

git rm file2.txt

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
    mv file1.txt main.js
    git add file1.txt
    git add main.js
    git status

git mv "file1.txt" "main.js"

terminal
    git mv "file1.txt" "main.js"
    git status

image.png

7-Ignoring file

terminal
    mkdir logs
    echo hello > logs/dev.log
    echo logs/ > .gitignore
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."
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0