[Git] Basic Git Commands

JudyΒ·2023λ…„ 1μ›” 1일
0

Dev

λͺ©λ‘ 보기
3/7

Follow these commands πŸ˜‰

ν•œκ΅­μ–΄ νŽ˜μ΄μ§€

1. (skip) Install git & Check version

git --version

2. (skip) Config name & email

  • Register your information in Git

    git config --global user.name "이름"
    git config --global user.email "이메일"

3. (skip) Initialize Git

  • Initialize the current directory to use git
  • If directory cloned from Github repository, don't initialize.
    # Initialize git
    git init

4. (skip) Check the status of Git

  • (output example)
    • On branch main (now you are in main branch)
    • No commits yet
    • nothing to commit
    git status

5. Staging

  • Add(upload) modified file to the stage
  • After then, check changed status using 'git status'
    git add filename / directory name / .

6. Commit

  • Create version
  • Add(upload) staged file to repository
    git commit -m "Message"

7. (skip) Check Commit history(log)

  • show detail logs about each commits
    (author, hash, date / time, commit messate)
  • (HEAD β†’ main) : Recent version
    git log
  • If you want to revert to the code at a specific commit point, you can use the command below.
  • Replace <commit-hash> with the hash value of the commit shown in the git log.
    git checkout <commit-hash>

8. (skip) Create ignore file

  • Create '.gitignore' file in project directory
  • You don't want to add file / directory, write name into '.gitignore'.

9. Create branch (Can skip if push to main)

    # Create branch
    git branch <new-branch-name>

    # Create branch & Switch into branch
    git checkout -b <new-branch-name>
  • View all branch information (Can Check the branch name you are currently working on)
    git branch
  • Merge branch
    • ex) If you merge Branch B to Branch A (or main)

      • git checkout A/main
      • git merge B
      git merge <branch name>
  • Delete branch
    git branch -d <branch-name>

10. (skip) Create repository

  • Verify that the repository is connected well
    git remote -v

11. (skip) Local - Repository

  git remote add origin https://github.com/<your-username>/<your-repo-name>.git

12. (skip) git clone

    git clone <github-repo-link>

13. git push (Pull Request)

  • Push to main / branch

  • Upload commit to github repository

    (main) git push origin main
    (branch) git push origin 브랜치 이름
  • Check the branch if the following error occurs
    * You should push to master branch

    git push -u origin main
    
    error: src refspec main does not match any
    error: failed to push some refs to 'https://github.com/Judy-Choi/41-minjoo.git'
  • Pull Request

    • If you pushed custom branch and ready to merge to master(main) branch,Β you can send a Pull Request (PR) to the project owner (or team leader) to merge(reflect) the work of the branch you worked on into the master branch.
    • If there is no conflict with the master branch after all reviews have been reflected, the PR is ready to merge into the master branch.

14. Pull from GitHub

  • If you updated the master branch through Pull Request, the local repository will now have different contents from the master in GitHub. Then you can use the git pull command to reflect the latest code from remote to your local repository.

  • We named the GitHub remote repository link origin, so you can get the master branch contents of GitHub repo through the command below.

    git pull origin master

15. (skip) Resolve Conflict

(Link) How to Resolve Conflict?

profile
NLP Researcher

0개의 λŒ“κΈ€