- 作者:20岁爱吃必胜客(坤制作人),近十年开发经验, 跨域学习者,目前于
新西兰奥克兰大学攻读IT硕士学位
。- 荣誉:
阿里云博客专家认证
、腾讯开发者社区优质创作者,在CTF省赛校赛多次取得好成绩。跨领域学习
,喜欢摄影、弹吉他、咏春拳。文章深入浅出、语言风趣
;爱吃必胜客社区创立者,旨在“发现美 欣赏美
- 学习系列专栏
。 Python学习宝库
。 网络安全学习宝库
Enter git commit -m "[commit message]"
to save the changes to your local repository
. You can enter anything for the commit message, but adding -m “[commit message]” specifies what this code change is doing, so it’s helpful to be clear and concise.
Enter git push origin [branch name]
to save your code changes to GitHub.
git push origin main
If you haven’t already done so, GitHub will prompt you to authenticate your identity. Enter your GitHub username and password. Once the authentication is done, the upload process will start. After it’s complete, you’ll see specific details about where the data was uploaded.
That’s it! You’ve successfully pushed your local files and folders to your GitHub repository.
To double-check that you pushed to GitHub successfully, open your GitHub repository web page. Your code changes should appear there.
PPS: GitHub has started naming the default branch main instead of master to migrate away from biased terminology (more details available here). In accordance with this industry-wide movement, we have also updated “Learn Git Branching” to use main instead of master in our lessons. This rename should be fairly consistent by now but if you notice any errors, feel free to submit a PR (or open an issue).
A commit in a git repository records a snapshot of all the (tracked) files in your directory. It’s like a giant copy and paste, but even better!
Git wants to keep commits as lightweight as possible though, so it doesn’t just blindly copy the entire directory every time you commit. It can (when possible) compress a commit as a set of changes, or a “delta”, from one version of the repository to the next.
Git also maintains a history of which commits were made when. That’s why most commits have ancestor commits above them – we designate this with arrows in our visualization. Maintaining history is great for everyone working on the project!
It’s a lot to take in, but for now you can think of commits as snapshots of the project. Commits are very lightweight and switching between them is wicked fast!
branch early, and branch often
Branches in Git are incredibly lightweight as well. They are simply pointers to a specific commit – nothing more. This is why many Git enthusiasts chant the mantra:
branch early, and branch often
Because there is no storage / memory overhead with making many branches, it’s easier to logically divide up your work than have big beefy branches.
When we start mixing branches and commits, we will see how these two features combine. For now though, just remember that a branch essentially says “I want to include the work of this commit and all parent commits.”
GitHub 是一个基于 Git 版本控制系统的代码托管平台,它提供了许多功能来管理代码、协作开发和跟踪项目变更。下面是一些 GitHub 的基本用法:
创建仓库(Repository): 在 GitHub 上创建一个新的代码仓库。点击页面右上角的“+”号,选择“New repository”并填写相关信息即可创建一个新的仓库。
克隆仓库(Clone Repository): 使用 Git 命令或者 GitHub Desktop 将远程仓库复制到本地进行编辑和开发。
bash
Copy code
git clone <repository_url>
提交更改(Commit Changes): 将更改保存到本地仓库。使用以下命令:
bash
Copy code
git add <file_name> # 将文件添加到暂存区
git commit -m "Commit message" # 将暂存区文件提交到本地仓库
git push origin <branch_name> # 将本地更改推送到远程仓库
分支管理(Branching): 创建新的分支,合并分支或删除分支。
bash
Copy code
git branch <branch_name> # 创建新分支
git checkout <branch_name> # 切换到指定分支
git merge <branch_name> # 将指定分支合并到当前分支
git branch -d <branch_name> # 删除指定分支
拉取更新(Pull Request): 提交更改并请求将其合并到主分支
(或其他分支)。在 GitHub 上创建 Pull Request,让其他人审查和讨论更改。
问题追踪(Issue Tracking): 创建问题(issue)来讨论和跟踪工作进度,可以在仓库的 Issues 标签下创建和管理。
GitHub Pages: 使用 GitHub 提供的服务托管静态网页。在仓库的 Settings 中启用 GitHub Pages,并选择要发布的内容目录。
这些是 GitHub 的一些基本用法,当然,GitHub 还有更多功能,比如团队协作、代码审查、Actions 等等,这些功能都有助于更好地管理和协作开发项目。