, 15 tweets, 5 min read Read on Twitter
Do you use #git but still don't really understand it?

Here's a 🔥 git crash course 🔥 to fix that 🎉


Git gives you a FULLY FEATURED repository on your local computer

This is different than other version control systems

Once you embrace that, you can start demystifying some of the git 'magic'

Think of files (and changes) as being in 5 different places, or "states"

- Working directory
- Staging (Index)
- Commit tree (local repo or HEAD)
- Stash
- Remote repo (@github, @Bitbucket, @gitlab, etc)

Think of moving files (or changes) between those places:

`git add` working dir => staging

`git commit` staging => HEAD

`git push` HEAD => remote repo

`git stash` working dir <=> stash

`git reset` and `git checkout` to pull from upstream

Why have a dedicated staging area?

So that you can choose and review which files and changes to commit before committing.

`git status` shows changes in both your working directory and staging, but think of them as separate things.

`git log` shows the history of commits your local repository

Learn to love `git log`

It's a snapshot of repo state: shows past commits as well as local HEAD, local branch, remote HEAD and remote branch

`git log --oneline` is compact way to view commit history

A branch is a reference to the tip of a line of commits

It automatically updates when new commits are added to that line

Making a new branch will diverge the tree at that point

A merge takes two branches and makes a NEW commit which combines them

If there are conflicts, you have to manually resolve them (no shortcuts!)

`git rebase` lets you rewrite commit history

Applies your current commits directly to branch HEAD

Can squash all your commits into one to clean up history

Don't do this to public (remote) commits!

Some people say you should only ever merge to keep your entire history

Some people say you should always rebase before merging into master to keep a clean history tree

I say: do whatever works for you and your team 🤷‍♂️

HEAD can point to a branch or a specific commit

If it points to an old commit, that's called a "detached HEAD"

Editing in a detached HEAD state is dangerous (can lose work or cause problems combining work)

Many git commands can operate on either: individual files, commits, or branches

This can cause a lot of confusion - so make sure you know what TYPE of object you're operating on

There are many ways to undo unwanted actions in git
Here are the most common:

unstage a file: `git reset [file]`

change last LOCAL commit: `git commit --amend`

erase local commit: `git reset [commit BEFORE that one]`

undo remote commit: `git revert [commit to undo]`

There's SO MUCH MORE I could have talked about!

What other things confuse you about git?

Comment below and I'll try to answer or find some resources for you 🙌
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Chris Achard
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!