有什么好看的三级片| 腊肉和什么菜炒好吃| 月经为什么是黑色的| 床上为什么会有跳蚤| 嘴唇肿了是什么原因| 米是什么结构| 经常长溃疡是什么原因引起的| 皮肤有白点是什么原因| spa按摩是什么意思| 香蕉与什么食物相克| 邪火是什么意思| 湿气重是什么原因造成的| 早上空腹喝淡盐水有什么好处| 高铁上什么东西不能带| 口干舌燥吃什么药最好| 慢性前列腺炎有什么症状| 梦见抽血是什么预兆| 蚊子怕什么植物| 男生什么时候会有生理反应| sansui是什么牌子| 鸡头米是什么| 肛门长肉球是什么原因| 舌苔黄腻吃什么药| 病人打白蛋白意味着什么| 签退是什么意思| 牛油是什么油| 安徽简称什么| 怀孕感冒了有什么好办法解决| 老是打饱嗝是什么原因| 舌头紫色是什么原因| 神经性耳鸣吃什么药| 西沙必利片治什么病| rds医学上什么意思| 滞气是什么意思| 莱猪是什么| 白介素高说明什么| zbc什么意思| 钙不能和什么一起吃| 7月9日是什么星座| met是什么意思| 样板间是什么意思| 纵横四海是什么意思| 瘫痪是什么意思| 老是瞌睡是什么原因| hiv弱阳性是什么意思| 福建为什么叫八闽| 在干什么| 属蛇女和什么属相最配| prn医学上是什么意思| 查血清能查出什么病| 酌情是什么意思| 勇者胜的上半句是什么| 霉菌性炎症用什么药效果最好| 数字17代表什么意思| 出水痘不能吃什么食物| 为什么蚊子咬了会起包| 鸡蛋和什么炒好吃| 八百里加急是什么意思| 下肢浮肿是什么原因引起的| pocky是什么意思| 咳嗽喉咙痛吃什么药| 系带割掉了有什么影响| 最小的一位数是什么| 草木皆兵是什么生肖| 内热是什么意思| 开普拉多的都是什么人| 仲夏是什么意思| 耳鸣脑鸣是什么原因引起的| 有什么功效| 五月十七号是什么星座| 左手发麻是什么病征兆| 肚子疼拉稀是什么原因| 睡觉掉床下是什么预兆| 一月8日是什么星座| 什么是非处方药| 5月14日是什么星座| 呼吸困难是什么原因引起的| 生理期肚子疼吃什么药| 脚底疼痛是什么原因| 嵌甲去医院挂什么科| 3的倒数是什么| 寻的部首是什么| 为伊消得人憔悴什么意思| 1967属什么生肖| 抽烟是什么感觉| 腿毛有什么用| 原研药是什么意思| 咽喉干燥是什么原因| 念力是什么意思| 水肿是什么意思| shadow是什么意思| 龋齿是什么样子的图片| 左手小手指麻木是什么原因引起的| 晚上睡觉喉咙干燥是什么原因| 肚脐眼疼吃什么药| 淋巴组织增生是什么意思| 什么情况下打破伤风| 水漫金山是什么生肖| 梦见借给别人钱是什么意思| 结婚10周年是什么婚| 鸡与什么生肖相合| 屁为什么是臭的| 农历8月20日是什么星座| 屌丝是什么| 感冒是什么原因引起的| 日央读什么| 233是什么意思啊| 此起彼伏是什么意思| 高考报名号是什么| 血小板分布宽度是什么意思| 什么是梦魇| 肌酐高是什么原因| 开光的手串有什么禁忌| ad是补什么的| 子宫内膜为什么会增厚| 尿生化是查什么的| 前列腺增生伴钙化是什么意思| 什么叫压缩性骨折| 儿童查微量元素挂什么科| 做梦放鞭炮什么意思| 痔疮的症状是什么| 1967属什么生肖| 艾滋病初期皮疹是什么样的| 什么是眩晕症| 是什么符号| 脑供血不足吃什么药效果好| 人乳头瘤病毒51型阳性是什么意思| alt医学上是什么意思| 外阴长什么样| 芙蕖是什么意思| 什么的蜻蜓| 牙疳是什么意思| 三伏天什么时候结束| 爱情是什么样| 粑粑是什么意思| g6pd筛查是检查什么| 高血压属于什么系统疾病| k3是什么| pussy 什么意思| 鼻塞有脓鼻涕吃什么药| 再接再厉后面接什么好| 秦始皇为什么焚书坑儒| 军士长是什么军衔| 印泥用什么能洗掉| 查胆囊挂什么科| 是什么药| 什么水能喝| 1994属什么生肖| 吃什么增强免疫力最快| 衾怎么读什么意思| 心率过高是什么原因| gin是什么意思| 色相是什么意思| 游离甲状腺素偏低是什么意思| 白球比例偏高说明什么| 肚子腹泻是什么原因| q1什么意思| 乳房疼痛应该挂什么科| 为什么床上有蚂蚁| 自缚是什么意思| feel什么意思| 梅花象征着什么| 虹膜是什么| 什么是比热容| 鼻窦粘膜增厚什么意思| 惊蛰吃什么| 灿字五行属什么| 梦见大白菜是什么意思| 心机什么意思| 大饼是什么意思| 血小板偏高是什么原因| 猕猴桃什么季节成熟| perrier是什么水| 淋巴结是什么原因引起的| 壁虎在家里是什么征兆| 九零年属什么生肖| 支原体是什么病| 西米露是什么做的| 木薯淀粉可以用什么代替| 2022年是什么生肖年| 六九是什么意思| 子宫增厚是什么原因| 梦见自己在洗澡是什么意思| 血管检查是做什么检查| 爱出汗是什么原因女人| 江字五行属什么| 水痘疫苗叫什么| 生活方式是什么意思| 苯甲酸钠是什么东西| 心肌梗塞是什么原因造成的| 双非是什么| 上海九院是什么医院| 92年是什么生肖| 12320是什么电话| 脚怕冷是什么原因引起的| 什么什么桑田| 促排卵吃什么药| 老鼠和什么属相相冲| 深井冰什么意思| 灵枢是什么意思| 一见如什么| 衍生物是什么意思| 为什么有两个六月| 7月份什么星座| 追悔莫及什么意思| 心脏做什么检查最准确| 有机会是什么意思| 梦见大狼狗是什么意思| eagle是什么意思| 能耐是什么意思| 好景不长是什么意思| ria是什么意思| 精血亏虚吃什么中成药| bjd娃娃是什么| 鼻子干燥是什么原因| 木乐读什么| 胸口出汗是什么原因| 皮肤粗糙缺什么维生素| 新生儿黄疸吃什么药| 金的部首是什么| 什么是红曲米| 暮雪是什么意思| 空气过敏是什么症状| 汗青是什么意思| 手癣用什么药膏效果好| 辟加木念什么| 94狗跟什么属相配最好| 头孢全名叫什么| 脑供血不足吃什么药| 脚气挂什么科室| 月亮是什么颜色| 石五行属什么| 王代表什么生肖| 地铁是什么| 奔现是什么意思| hia是什么意思| 梅毒长什么样| 1834是什么意思| 腊月二十三是什么星座| 儿童补钙吃什么| 心脏早搏吃什么药最好| 肩膀疼挂什么科室最好| 感冒吃什么药最快| 经血是什么血| 中专是什么学历| 复试是什么意思| 什么花没有叶子| 多吃山竹有什么好处| 甲状腺球蛋白抗体低说明什么| 从此萧郎是路人是什么意思| 白羊女和什么星座最配| 羡慕是什么意思| 肢体拘挛是什么意思| 脖子粗挂什么科| 术后血压低什么原因| 吃什么降火| 躯体化障碍是什么病| fnc是什么意思| est什么意思| 看指甲去医院挂什么科| 农历10月14日是什么星座| 小寒节气的含义是什么| 2017属什么生肖| 榴莲有什么营养价值| 百度
Skip to content
Git remote illustration

Git Guide

Everything you need to know about Git, from getting started to advanced commands and workflows.

Quick links:

What is Git?

Git is a distributed version control software. Version control is a way to save changes over time without overwriting previous versions. Being distributed means that every developer working with a Git repository has a copy of that entire repository – every commit, every branch, every file. If you're used to working with centralized version control systems, this is a big difference!

Whether or not you've worked with version control before, there are a few things you should know before getting started with Git:

  • Branches are lightweight and cheap, so it's OK to have many of them
  • Git stores changes in SHA hashes, which work by compressing text files. That makes Git a very good version control system (VCS) for software programming, but not so good for binary files like images or videos.
  • Git repositories can be connected, so you can work on one locally on your own machine, and connect it to a shared repository. This way, you can push and pull changes to a repository and easily collaborate with others.

What is Git Written in?

The tools that make up the core Git distribution are written in C, Shell, Perl, and Tcl. You can find Git's source code on GitHub under git/git.

Why Use Git?

Version control is very important – without it, you risk losing your work. With Git, you can make a "commit", or a save point, as often as you'd like. You can also go back to previous commits. This takes the pressure off of you while you're working. Commit often and commit early, and you'll never have that gut-sinking feeling of overwriting or losing changes.

There are many version control systems out there – but Git has some major advantages.

Speed

Like we mentioned above, Git uses SHA compression, which makes it very fast.

Merge conflicts

Git can handle merge conflicts, which means that it's OK for multiple people to work on the same file at the same time. This opens up the world of development in a way that isn't possible with centralized version control. You have access to the entire project, and if you're working on a branch, you can do whatever you need to and know that your changes are safe.

Cheap branches

Speaking of branches, Git offers a lot of flexibility and opportunity for collaboration with branches. By using branches, developers can make changes in a safe sandbox.

Instead of only committing code that is 100% sure to succeed, developers can commit code that might still need help. Then, they can push that code to the remote and get fast feedback from integrated tests or peer review.

Without sharing the code through branches, this would never be possible.

Ease of roll back

If you make a mistake, it's OK! Commits are immutable, meaning they can't be changed. (Note: You can change history, but it will create new replacement commits instead of editing the existing commits. More on that later!) This means that if you do make a mistake, even on an important branch, like main, it's OK. You can easily revert that change, or roll back the branch pointer to the commit where everything was fine.

The benefits of this can't be overstated. Not only does it create a safer environment for the project and code, but it fosters a development environment where developers can be braver, trusting that Git has their back.

How Do I Use Git?

Learning Git Basics

If you're getting started with Git, a great place to learn the basic commands is the Git Cheat sheet. It's translated into many languages, open source as a part of the github/training-kit repository, and a great starting place for the fundamentals on the command line.

Some of the most important and most used commands that you'll find there are:

  • git clone [url]: Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits.
  • git status: Always a good idea, this command shows you what branch you're on, what files are in the working or staging directory, and any other important information.
  • git branch: This shows the existing branches in your local repository. You can also use git branch [branch-name] to create a branch from your current location, or git branch --all to see all branches, both the local ones on your machine, and the remote tracking branches stored from the last git pull or git fetch from the remote.
  • git checkout [branch-name]: Switches to the specified branch and updates the working directory.
  • git add [file]: Snapshots the file in preparation for versioning, adding it to the staging area.
  • git commit -m "descriptive message": Records file snapshots permanently in the version history.
  • git pull: Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge.
  • git push: Uploads all local branch commits to the remote.
  • git log: Browse and inspect the evolution of project files.
  • git remote -v: Show the associated remote repositories and their stored name, like origin.

If you're looking for more GitHub-specific technical guidance, check out GitHub's help documentation or our GitHub for Developers series on YouTube.

Getting Started With the Git Workflow

Depending on your operating system, you may already have Git installed. But, getting started means more than having the software! To get started, it's important to know the basics of how Git works. You may choose to do the actual work within a terminal, an app like GitHub Desktop, or through GitHub.com. (Note: while you can interact with Git through GitHub.com, your experience may be limited. Many local tools can give you access to the most widely used Git functionalities, though only the terminal will give you access to them all.)

There are many ways to use Git, which doesn't necessarily make it easier! But, the fundamental Git workflow has a few main steps. You can practice all of these in the Introduction to GitHub Learning Lab course.

Create a branch

The main branch is usually called main. We want to work on another branch, so we can make a pull request and make changes safely. To get started, create a branch off of main. Name it however you'd like – but we recommend naming branches based on the function or feature that will be the focus of this branch. One person may have several branches, and one branch may have several people collaborate on it – branches are for a purpose, not a person. Wherever you currently "are" (wherever HEAD is pointing, or whatever branch you're currently "checked out" to) will be the parent of the branch you create. That means you can create branches from other branches, tags, or any commit! But, the most typical workflow is to create a branch from main – which represents the most current production code.

Make changes (and make a commit)

Once you've created a branch, and moved the HEAD pointer to it by "checking out" to that branch, you're ready to get to work. Make the changes in your repository using your favorite text editor or IDE.

Next, save your changes. You're ready to start the commit!

To start your commit, you need to let Git know what changes you'd like to include with git add [file].

Once you've saved and staged the changes, you're ready to make the commit with git commit -m "descriptive commit message".

Push your changes to the remote

So far, if you've made a commit locally, you're the only one that can see it. To let others see your work and begin collaboration, you should "push" your changes using git push. If you're pushing from a branch for the first time that you've created locally, you may need to give Git some more information. git push -u origin [branch-name] tells Git to push the current branch, and create a branch on the remote that matches it with the same name – and also, create a relationship with that branch so that git push will be enough information in the future.

By default, git push only pushes the branch that you've currently checked out to.

Sometimes, if there has been a new commit on the branch on the remote, you may be blocked from pushing. Don't worry! Start with a simple git pull to incorporate the changes on the remote into your own local branch, resolve any conflicts or finish the merge from the remote into the local branch, and then try the push again.

Open a pull request

Pushing a branch, or new commits, to a remote repository is enough if a pull request already exists, but if it's the first time you're pushing that branch, you should open a new pull request. A pull request is a comparison of two branches – typically main, or the branch that the feature branch was created from, and the feature branch. This way, like branches, pull requests are scoped around a specific function or addition of work, rather than the person making the changes or the amount of time the changes will take.

Pull requests are the powerhouse of GitHub. Integrated tests can automatically run on pull requests, giving you immediate feedback on your code. Peers can give detailed code reviews, letting you know if there are changes to make, or if it's ready to go.

Make sure you start your pull requests off with the right information. Put yourself in the shoes of your teammates, or even of your future self. Include information about what this change relates to, what prompted it, what is already done, what is left to do, and any specific asks for help or reviews. Include links to relevant work or conversations. Pull request templates can help make this process easy by automating the starting content of the body of pull requests.

Collaborate

Once the pull request is open, then the real fun starts. It's important to recognize that pull requests aren't meant to be open when work is finished. Pull requests should be open when work is beginning! The earlier you open a pull request, the more visibility the entire team has to the work that you're doing. When you're ready for feedback, you can get it by integrating tests or requesting reviews from teammates.

It's very likely that you will want to make more changes to your work. That's great! To do that, make more commits on the same branch. Once the new commits are present on the remote, the pull request will update and show the most recent version of your work.

Merge into main

Once you and your team decide that the pull request looks good, you can merge it. By merging, you integrate the feature branch into the other branch (most typically the main branch). Then, main will be updated with your changes, and your pull request will be closed. Don't forget to delete your branch! You won't need it anymore. Remember, branches are lightweight and cheap, and you should create a new one when you need it based on the most recent commit on the main branch.

If you choose not to merge the pull request, you can also close pull requests with unmerged changes.

Getting Started With GitHub

If you're wondering where Git ends and GitHub begins, you're not alone. They are tied closely together to make working with them both a seamless experience. While Git takes care of the underlying version control, GitHub is the collaboration platform built on top of it. GitHub is the place for pull requests, comments, reviews, integrated tests, and so much more. Most developers work locally to develop and use GitHub for collaboration. That ranges from using GitHub to host the shared remote repository to working with colleagues and capitalizing on features like protected branches, code review, GitHub Actions, and more.

The best place to practice using Git and GitHub is the Introduction to GitHub Learning Lab course.

If you already know Git and need to sign up for a GitHub account, head over to github.com.

Contribute to this article on GitHub.

Get started with git and GitHub

Review code, manage projects, and build software alongside 40 million developers.

Sign up for GitHub Sign in
病毒感染咳嗽吃什么药 幽门螺杆菌什么药最好 慢阻肺吃什么药 令妹是什么意思 马赛克什么意思
胡子白了是什么原因 早泄要吃什么药 肩周炎吃什么药好得快 岳云鹏为什么这么火 单宁是什么
三伏天吃什么对身体好 喉咙有异物感挂什么科 人为什么要喝酒 硅胶是什么材质 细思极恐是什么意思
碧玺五行属什么 什么叫环比 小孩腰疼是什么原因引起的 肛门瘙痒是什么问题 百香果有什么功效
一个家庭最重要的是什么hcv9jop6ns3r.cn 尿酸高有什么反应hcv8jop1ns1r.cn 犒劳自己是什么意思hcv9jop4ns4r.cn 脚后筋疼是什么原因引起的cj623037.com 圣是什么生肖hcv9jop2ns3r.cn
什么叫流年hcv8jop7ns4r.cn 7月份什么星座hcv9jop1ns0r.cn 咳嗽嗓子疼吃什么药qingzhougame.com 月与什么有关hcv7jop5ns3r.cn 五四运动是什么hcv9jop7ns0r.cn
寒碜是什么意思hcv8jop8ns2r.cn 犒劳是什么意思hcv9jop2ns4r.cn ooc是什么意思hcv8jop2ns9r.cn 什么运动瘦肚子dayuxmw.com 空白是什么意思hcv7jop4ns8r.cn
甲沟炎去医院挂什么科hcv9jop3ns3r.cn 6点是什么时辰hcv7jop9ns7r.cn 眼拙是什么意思hcv9jop2ns5r.cn 肺热咳嗽吃什么药hcv9jop4ns8r.cn 胃疼应该挂什么科hcv8jop6ns2r.cn
百度