alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

[1093] Git command examples

Ref: Git-Commands


Here are some common Git command examples along with explanations:

Basic Commands

  1. Initialize a Repository:

    git init

    Initializes a new Git repository in the current directory.

  2. Clone a Repository:

    git clone https://github.com/user/repo.git

    Creates a copy of an existing repository from a remote URL to your local machine.

  3. Check Repository Status:

    git status

    Displays the state of the working directory and the staging area.

  4. Stage Changes:

    git add filename
    git add .

    Adds changes in the specified file (or all changes with .) to the staging area.

  5. Commit Changes:

    git commit -m "Your commit message"

    Records changes in the repository with a descriptive message.

  6. Show Commit History:

    git log

    Lists the commit history for the repository.

Branching and Merging

  1. Create a New Branch:

    git branch new-branch

    Creates a new branch called new-branch.

  2. Switch to a Branch:

    git checkout branch-name

    Switches to the specified branch.

  3. Merge Branches:

    git merge branch-name

    Merges the specified branch into the current branch.

Remote Repositories

  1. Add a Remote Repository:

    git remote add origin https://github.com/user/repo.git

    Adds a remote repository with the name origin.

  2. Push Changes to Remote:

    git push origin branch-name

    Pushes local changes to the specified branch of the remote repository.

  3. Pull Changes from Remote:

    git pull origin branch-name

    Fetches and merges changes from the specified branch of the remote repository into the current branch.

Example Workflow

  1. Initialize a Repository:

    git init
  2. Create and Switch to a New Branch:

    git branch new-feature
    git checkout new-feature
  3. Stage and Commit Changes:

    git add .
    git commit -m "Add new feature"
  4. Push to Remote:

    git push origin new-feature
  5. Merge New Feature into Main Branch:

    git checkout main
    git merge new-feature
    git push origin main

Explanation

  • git init: Sets up a new Git repository.
  • git clone: Clones an existing repository.
  • git status: Shows the status of the working directory.
  • git add: Stages changes for the next commit.
  • git commit: Commits the staged changes.
  • git log: Displays the commit history.
  • git branch: Manages branches.
  • git checkout: Switches branches.
  • git merge: Merges branches.
  • git remote: Manages remote repositories.
  • git push: Pushes changes to a remote repository.
  • git pull: Fetches and merges changes from a remote repository.

These commands cover a wide range of common Git operations and should help you manage your repositories effectively. If you have any specific questions or need more details, feel free to ask! 😊

posted on   McDelfino  阅读(3)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-01-15 【523】python存储变量方法
2021-01-15 【522】深度学习超参数调节
2019-01-15 【348】通过 Numpy 创建各式各样的矩阵
2019-01-15 【347】将jupyter notebook嵌入博客园
2018-01-15 【290】Python 常用说明
2018-01-15 【290】Python 模块(自定义包)
2018-01-15 【290】Python 函数
点击右上角即可分享
微信分享提示