gitlab 基本指令

A little lookup for commands I use frequently

  1. Commit all edited files and add a message

    git commit -a -m “My commit”

  2. Add all new files

    git add .

  3. Perform a pull operation

    git pull REMOTENAME BRANCHNAME

  4. Perform a push operation

    git push REMOTENAME BRANCHNAME

  5. Prune all stale remote tracking branches

    git remote prune REMOTENAME

  6. Create a branch

    git branch BRANCHNAME

  7. View branches

    git branch

  8. Checkout a different branch

    git checkout BRANCHNAME

  9. Checkout a remote branch

    git checkout -b LOCALBRANCHNAME origin/REMOTEBRANCHNAME

  10. Merge the changes made in another branch in to the current branch

    git merge BRANCHNAME

  11. Delete a local branch

    git branch -d BRANCHNAME

  12. Delete a remote branch

    git push origin :BRANCHNAME

  13. Delete a remote branch (sexier syntax)

    git push origin –delete BRANCHNAME

  14. Scrap uncommitted state and return the working tree to the last committed state

    git reset –hard HEAD

  15. Delete the latest commit, and return to the one previous (one before HEAD)

    git reset –hard HEAD~1

  16. Return a single file to it’s last committed state

    git checkout – FILENAME
    git checkout HEAD FILENAME
    Git log
    git log
    git log –pretty=oneline
    git log –pretty=short

  17. Cherry pick commits and apply them to another branch (first grab the commit ID from the branch with said commit, then checkout the branch you wish to apply the commit to)

    git cherry-pick COMMIT-ID

  18. Stash uncommitted changes

    git stash save “message”

  19. Apply stashed changes somewhere

    git stash apply

  20. Stop a file being tracked (but do not delete it from the working directory, add to .gitignore etc after this)

    git rm –cached

03-08
### GitLab 入门指南和功能介绍 #### 一、GitLab 基本概述 GitLab 不仅仅是一个代码托管平台,更是一个集成了多种 DevOps 工具的强大平台,旨在提升团队协作效率与代码质量。对于开发者而言,掌握其基本使用方法及高级特性至关重要[^1]。 #### 二、创建仓库并初始化项目 当首次启动新项目时,在本地计算机上执行如下命令来设置新的 Git 库: ```bash git init ``` 接着可按照需求向其中添加文件,并利用 `git add .` 来标记这些更改以便后续提交。之后便能通过特定指令将改动记录至历史版本中: ```bash git commit -m "Initial project setup" ``` 此过程同样适用于更新现有资源——只需确保每次修改后都及时保存变更日志[^2]。 #### 三、管理分支策略 为了更好地组织开发流程,通常会采用多分支管理模式。例如,“develop” 分支常用于集成来自不同成员的功能改进;而 “master” 则保持稳定状态只接收经过充分测试后的成果。具体操作方式包括但不限于以下几种情形: - 当远程不存在 develop 分支时,可以在本地建立并向远端推送; ```bash git branch develop git push -u origin develop ``` - 若已存在于云端,则直接检出最新版即可; ```bash git checkout -b develop origin/develop ``` - 对于想要合并入主线的新特性,建议先同步最新的主干内容再做合并不失为一种良好习惯: ```bash git pull origin git merge feature/new-feature-name ``` 上述做法有助于减少潜在冲突的发生几率,保障整个项目的顺利推进[^4]。 #### 四、配置 SSH 密钥提高安全性 为了让日常交互更为便捷安全,推荐每位使用者为自己生成一对专属SSH密钥对,并将其公钥部分注册到个人账户下。这一步骤可通过下面两条简单命令快速完成: ```bash ssh-keygen -t rsa -C "your_email@example.com" cat ~/.ssh/id_rsa.pub ``` 最后复制输出结果里的字符串粘贴进 GitLab 用户界面指定位置即告大功告成[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值