首页 > 其他分享 >[1093] Git command examples

[1093] Git command examples

时间:2025-01-15 12:54:06浏览次数:1  
标签:git remote repository Git command examples branch new changes

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!

标签:git,remote,repository,Git,command,examples,branch,new,changes
From: https://www.cnblogs.com/alex-bn-lee/p/18672787

相关文章

  • [1092] Git Tutorial
    Ref:GitTutorial-W3SchoolUsingGitwithCommandLinegit--versiongitversion2.30.2.windows.1ConfigureGitgitconfig--globaluser.name"w3schools-test"gitconfig--globaluser.email"test@w3schools.com"CreatingGitFolderm......
  • Git使用
    配置查看当前系统的Git配置gitconfig--list设置当前主机的Git的账户名及邮箱地址gitconfig--globaluser.name"YourName"gitconfig--globaluser.email"email@example.com"项目在远程拉取代码gitclonehttps://github.com/liduchang/redis初始化Git项目git......
  • [SNCPC2019] Digit Mode
    前言不管从实现方式到智慧程度都是数位\(\rm{dp}\)好题,写一下思路首先你发现常规的数位\(\rm{dp}\)方法不可以实现原因是不能对于一个数求出其\(m(x)\)容易考虑到逆向思考,你钦定\(m(x)\)的值,看有多少个\(x\)满足此要求怎么做?先考虑最简单的情况,如果从\(......
  • Gitlab搭建npm仓库
    由于图片和格式解析问题,为了更好阅读体验可前往阅读原文:::warning使用gitlab的仓库注册表特性需要版本14.0+,如果你的版本比较低,请先根据自己的需求合理升级后再使用:::npm私有仓库的搭建方式有很多种,比如使用docker(阅读此篇),这里讲述如何使用gitlab作为npm仓库方法,gitlab......
  • linux编译protobuf-3.3.0 报错 automake-1.14 command not found 解决
    目录源码下载配置编译解决REFlinux编译protobuf-3.3.0报错automake-1.14:commandnotfound解决源码下载https://github.com/protocolbuffers/protobuf/releases配置编译配置完成后,编译出错./configuremakecd.&&/bin/bash/tmp/protobuf-3.3.0/miss......
  • git整体使用流程
    一、场景说明本地有文件想在github创建一个远程仓库在本地修改,同时同步到远端二、流程设置用户名和邮箱目的:标识每次提交者的身份设置全局用户名:gitconfig--globaluser.name"YourName"设置全局邮箱:gitconfig--globaluser.email"your.email@example.com"......
  • VS Code 中,GitLens 和 Git Graph
    在VSCode中,GitLens和GitGraph插件是两款非常强大的Git扩展,可以显著增强Git操作的效率和可视化功能。1.安装GitLens和GitGraph插件1.1安装GitLens插件GitLens是一个强大的VSCode扩展,用于增强Git的功能,提供更多的提交历史、作者信息、文件变更......
  • Windows下Git Bash的tar命令使用
    Administrator@WIN-5B2ST4S1K5HMINGW64~/Documents/spark$lsspark-3.5.4-bin-hadoop3.tgzspark-3.5.4-bin-without-hadoop.tgzAdministrator@WIN-5B2ST4S1K5HMINGW64~/Documents/spark$tar-xspark-3.5.4-bin-hadoop3.tgz./tar:Refusingtoreadarchivecon......
  • GitLab 国际站中国大陆等地区停服,如何将数据快速迁移到云效
    代码托管平台GitLab国际站(GitLab.com)近日发布公告,官宣即将停止对中国大陆、香港、澳门地区的用户账号提供服务,并提供60天过渡期自行迁移账户数据,超期未迁移的账号可能会被GitLab清除。这一重要决策引起了全球开发者的广泛关注和讨论。为了承接本次调整受影响地区的用户,GitL......
  • GitLab 国际站中国大陆等地区停服,如何将数据快速迁移到云效
    代码托管平台GitLab国际站(GitLab.com)近日发布公告,官宣即将停止对中国大陆、香港、澳门地区的用户账号提供服务,并提供60天过渡期自行迁移账户数据,超期未迁移的账号可能会被GitLab清除。这一重要决策引起了全球开发者的广泛关注和讨论。为了承接本次调整受影响地区的用户,GitL......