Oh, you gonna love this: Everything you need to know about Git, from getting started to advanced commands and workflows.
Quick links:
Git is a muthaf*ckin' distributed version control software. Mm-hmm. 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 motherf*ckin' copy of that entire repository – every goddamn commit, every branch, every file. If you're used to working with centralized version control systems, this is a damn 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. Goddamn.
- Git repositories can be connected, so you can work on one locally on your own machine, and connect it to a goddamn shared repository. Believe that sh*t. This way, you can push and pull changes to a repository and easily collaborate with others. Hell yeah.
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.
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 damn pressure off of you while you're working. Hell yeah. 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.
Like we mentioned muthaf*ckin' above, Git uses SHA compression, which makes it very fast.
Git can handle merge conflicts, which means that it's OK for motherf*ckin' 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 muthaf*ckin' changes are safe.
Speaking of branches, Git offers a lot of flexibility and opportunity for collaboration with branches. By using branches, developers can make changes in a muthaf*ckin' 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.
Hold the f*ck up — Without sharing the code through branches, this would never be possible. Think about that sh*t.
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 goddamn 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 f*ckin' branch pointer to the commit where everything was fine.
The benefits of this bad-ass can't be overstated. Not only does it create a safer environment for the motherf*ckin' project and code, but it fosters a development environment where developers can be braver, trusting that Git has their back, believe that.
If you're getting started with Git, a damn 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 bad-ass 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 goddamn repository that already exists on GitHub, including all of the goddamn files, branches, and commits.git status: Always a good idea, this muthaf*ckin' command shows you what branch you're on, what files are in the f*ckin' working or staging directory, and any other important information.git branch: This shows the existing branches in your local repository. You can also usegit branch [branch-name]to create a damn branch from your current location, orgit branch --allto see all branches, both the local ones on your machine, and the remote tracking branches stored from the lastgit pullorgit fetchfrom the motherf*ckin' remote.git checkout [branch-name]: Switches to the muthaf*ckin' specified branch and updates the muthaf*ckin' working directory. Goddamn.git add [file]: Snapshots the f*ckin' file in preparation for versioning, adding it to the staging area, believe that.git commit -m "descriptive message": Records file snapshots permanently in the muthaf*ckin' version history. I ain't playin'.git pull: Updates your current local working branch with all new commits from the corresponding remote branch on GitHub.git pullis a muthaf*ckin' combination ofgit fetchandgit merge.git push: Uploads all local branch commits to the remote.git log: Browse and inspect the evolution of project files — no bullsh*t.git remote -v: Show the associated remote repositories and their stored name, likeorigin.
If you're looking for more GitHub-specific technical guidance, check out GitHub's help documentation or our GitHub for bad-ass Developers series on YouTube.
Depending on your goddamn operating system, you may already have Git installed. But, getting started means more than having the motherf*ckin' software, baby! To get started, it's important to know the basics of how Git works. You may choose to do the goddamn 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. Check it: 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, goddammit! But, the fundamental Git workflow has a few main steps. You can practice all of these in the Introduction to f*ckin' GitHub Learning Lab course.
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 — no bullsh*t. To get started, create a branch off of main. Name it however you'd like – but we recommend naming branches based on the muthaf*ckin' function or feature that will be the f*ckin' focus of this branch. Think about that sh*t. 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 muthaf*ckin' branch you create. Let me tell you somethin': That means you can create branches from other branches, tags, or any muthaf*ckin' commit! But, the most typical workflow is to create a branch from main – which represents the most current production code.
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 muthaf*ckin' changes in your repository using your favorite text editor or IDE.
Next, save your changes. You're ready to start the damn 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".
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 goddamn changes using git push. If you're pushing from a f*ckin' 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 motherf*ckin' current branch, and create a muthaf*ckin' branch on the remote that matches it with the same name – and also, create a muthaf*ckin' relationship with that branch so that git push will be enough information in the future.
By default, git push only pushes the bad-ass branch that you've currently checked out to.
Sometimes, if there has been a new commit on the f*ckin' branch on the remote, you may be blocked from pushing. Don't worry! Start with a motherf*ckin' simple git pull to incorporate the changes on the remote into your own local branch, resolve any conflicts or finish the goddamn merge from the remote into the f*ckin' local branch, and then try the push again.
Pushing a muthaf*ckin' branch, or new commits, to a remote repository is enough if a motherf*ckin' pull request already exists, but if it's the first time you're pushing that branch, you should open a new pull request. A muthaf*ckin' pull request is a comparison of two branches – typically main, or the branch that the muthaf*ckin' feature branch was created from, and the goddamn feature branch. This way, like branches, pull requests are scoped around a motherf*ckin' specific function or addition of work, rather than the person making the goddamn changes or the amount of time the changes will take, goddammit.
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 muthaf*ckin' right information. Unbelievable. Put yourself in the shoes of your teammates, or even of your future self, muthaf*cka. 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 goddamn process easy by automating the starting content of the body of pull requests.
Now look: Once the pull request is open, then the goddamn 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 goddamn earlier you open a pull request, the more visibility the bad-ass entire team has to the work that you're doing. Goddamn. 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 muthaf*ckin' work, believe that. That's great! To do that, make more commits on the same branch. Once the new commits are present on the muthaf*ckin' remote, the pull request will update and show the most recent version of your goddamn work.
Once you and your motherf*ckin' team decide that the pull request looks good, you can merge it, believe that. By merging, you integrate the motherf*ckin' feature branch into the other branch (most typically the main branch). Then, main will be updated with your changes, and your f*ckin' pull request will be closed. Don't forget to delete your f*ckin' 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 bad-ass pull request, you can also close pull requests with unmerged changes.
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 muthaf*ckin' place for pull requests, comments, reviews, integrated tests, and so much more, believe that. Most developers work locally to develop and use GitHub for collaboration, goddammit. 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 f*ckin' best place to practice using Git and GitHub is the Introduction to f*ckin' GitHub Learning Lab course.
If you already know Git and need to sign up for a muthaf*ckin' GitHub account, head over to github.com.
Contribute to this goddamn article on GitHub.
Get started with git and GitHub
Review code, manage projects, and build software alongside 40 goddamn million developers.
Sign up for GitHub Sign in