6626070
2997924

PL00, GIT

Back to the previous pagepage management
List of posts to read before reading this article


Contents


version

$ git --version





Basic

Installation

# git
$ sudo apt-get install git

# git lfs
$ sudo apt install curl
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt install git-lfs




user information

identification

$ git config --list
$ git config --global user.name
$ git config --global user.email
$ git config --global core.editor




enrollment

$ git config --global user.name [user_name]
$ git config --global user.email [user_email_address]
$ git config --global core.editor "[editor]"




credential manager

$ git credential-manager uninstall
$ git credential-manager install




.gitignore

# ignore all .a files
*.a

# but do track lib.a, even though you're ignoring .a files above
!lib.a

# only ignore the TODO file in the current directory, not subdir/TODO
/TODO

# ignore all files in any directory named build
build/

# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt

# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf

Version control

Working directory initiailization

$ git init 
$ git init .
$ git init [folder_name]    # mkdir [folder_name];cd [folder_name];git init





Working directroy to staging area

$ git add [file_name]





Staging area to repository

$ git commit -m "[massage]"       # staging area to repository [commit]
$ git commit -am "[massage]"      # working directory to staging area to repository [add + commit]
$ git commit --amend              # amend(modifty)





Check status

$ git status
$ git rm --cached [filename]





Show changes

$ git diff





Show version log

$ git log --pretty=format:"%h %s" --graph    # simple message log
$ git log                                    # message log
$ git log --stat                             # message log with file name
$ git log -p                                 # message log with file name and changed contents(diff)
$ git log --all                              # message all log
$ git log --all --graph                      # graphical message all log
$ git log --all --graph --oneline            # oneline graphical message all log
$ git reflog





Return to past status(change only head)

$ git checkout [commit_id_on_log]     # return to a moment in past
$ git checkout master                 # return back to present





Reset to past status(change head with master)

$ git reset --help                        # reset argument
$ git reset HEAD [file]                   # cancel "a added file"
$ git reset HEAD                          # cancel "all added file"
$ git reset --soft HEAD^                  # cancel "a latest commited file into staging(status before commit)"
$ git reset --hard [commit_id_on_log]     # reset to a moment in past





Make previous status as new status add

$ git revert [commit_id_for_master_on_log]





Branch, Conflict

$ git log --all --graph --oneline
$ git branch [branch_name]          # create branch
$ git branch -m [new_branch_name]   # rename branch
$ git branch -d [branch_name]       # delete fully merged branch
$ git branch -D [branch_name]       # delete branch (even if not merged)
$ git checkout [branch_name]
$ git merge [branch_name]





Remote repository : Back-up

https

$ git remote add [alias_of_URL] [URL]     # connect remote repository
$ git remote                              # connected remote repository
$ git remote -v                           # connected remote repository with URL
$ git push [-u|--set-upstream] origin master               # up-stream setting





ssh

URL

$ ssh-keygen -t rsa -C [your_email_address]    # generate key
$ eval "$(ssh-agent -s)"                       # add key to agent(1)
$ ssh-add ~/.shh/id_rsa                        # add key to agent(2)
the rest of the process

Settings image


SSH and GPG keys image


New SSH key image


key : $ vim ~/.ssh/id_rsa.pub
image


Add SSH key
image






back-up

$ git clone
$ git pull
$ git push
$ git push -f                # push by force





Cooperation

README.md

title

# title1
## title2
### title3
#### title4
##### title5
###### title6



code

# include <stdio.h>

int main(void){
    printf("hello, world");
    return 0;
}




link
PL00-GIT




unordered list

  • git
    • g
    • i
    • t
      • hub


quotation

hello, world




table

name age sex
a 23 m
b 43 w
c 36 m




etc

hello
hello





Make zip file for sending this to someone

$ git archive --format=zip master -o [file_name.zip]
$ git archive --format=zip master -o [../file_name.zip]





Update remote repository

$ git clone
$ git fetch
$ git merge FETCH_HEAD
$ git merge [remote_branch_name]
$ git pull              # git fetch; git merge FETCH_HEAD
$ git push
$ git push -f                # push by force





Reset & revert





Cherry-pick & rebase





List of posts followed by this article


Reference


OUTPUT