Hopefully, no one needs to sell you on GitHub - the world's largest open source community. GitHub is home for most developers - a fast flexible social environment to build personal projects, support enterprises and collaborate on open source technologies.
The underpinnings of GitHub is Git - a free, open source, cross-platform and highly productive distributed version control system. GitHub conveniently wraps all of Git's features into polished UI tools for your chosen development platform, namely:
But you are a geek. And what appeals more to your inner nerdiness than pure text on a bland terminal window. Nothing like passer-by's not having a clue as to what you are up to! Everything you do through the GitHub UI tools, first began life as command line tools via the the Git CLI. And it is incredibly powerful.
This article doesn't have screenshots and memes. Instead it aims to be a straight up cheat sheet of Git CLI commands. The best news is that all of the commands work the exact same way on Linux, Mac OS/OSX and Windows.
First, let's get a basic command line refresher under our belt - most commands work consistently across the Bash and DOS command prompts.
List Directory contents - provides a list of all files/folders in given working directory.
Change Directory - navigates to given folder as working directory.
cd / navigates to root folder and
cd .. traverses one level up to the parent directory of the current working directory.
Make Directory - creates a new folder in place.
open -a "TextEdit" .bash_profile
Open the bash_profile file in TextEdit on a Mac. If you're on Linux/OSX systems, the bash_profile is the user's personal initialization file, executed by login shells as the terminal command prompt starts up.
PS1="\u @ \t: 🤘 "
Also on Linux/OSX, the Bash shell command prompt can be customized using PS1-4 Prompt Statements - essentially environment variables. You could add PS variables in your bash_profile to customize the command prompt. Above is mine with an Emoji in my command prompt - because why not!
Clears terminal window of past commands and outputs - provides fresh command prompt.
Now let's dig into the Git CLI. This is not an exhaustive list, but focuses on the most frequently used commands.
git config --global user.name "<UserName>"
Sets the name you want attached to your commit transactions.
git config --global user.email "<UserEmail>"
Sets the email you want attached to your commit transactions.
git init <ProjectName>
Initializes a new Git repository. Transforms a regular folder into a directory that can accept Git commands.
git clone <RemoteGitHubURL>
Copies down a remote GitHub repository along with all the version history to a local working directory. Maps the directory for further commands.
Checks the status of a given repository. Lists th working branch and any new/changed files that need to be committed.
Shows the file differences not yet staged.
git add <FileName>
Brings new files in your repository to Git's attention for tracking. Includes the file in the repository snapshot for versioning.
git add .
Adds a batch of files to Git's tracking in a local working directory. Adds everything in one swoop. This command could also add files with a specific extension or other filters.
git reset <FileName>
Unstages the named file from the repository snapshot, but preserves its contents.
Shows all the local branches in the current repository.
git branch <BranchName>
Creates a new branch in the current repository.
git checkout master/<BranchName>
A navigational command that switches the working directory to master/named branch. The files are representative of the state of master/branch.
git commit -m "<CommitMessage>"
Commit changes that you have made in your working directory with a descriptive message.
git merge <BranchName>
Merge changes made in a given branch to the master branch. Makes updates visible to all repository collaborators.
git branch -d <BranchName>
Deletes a branch after changes have been merged with master branch.
git remote add origin <RemoteURL>
Introduces local Git to remote repository (typically GitHub). Adds hooks for pull/push for syncing with remote source.
git push --set-upstream origin master
Pushes local repository changes to a remote master branch in a linked repository (again, probably GitHub). Syncs remote with local.
git pull origin master
Pulls down a master/named branch from a linked remote repository to a local working directory. Syncs local with remote.
Fogot something? Pull up the Git CLI Help to look up commands with the option to dig further into each command.
As you collaborate more and more on GitHub projects, a few tips may be helpful:
We at Telerik, love open source and love GitHub. You'll find some very popular GitHub repositories maintained by Telerik - and we are happy to share. So jump in, clone it, use it, fork it and contribute back.
A cheat sheet of commands does not need a conclusion, right? So keep that terminal window open, reference this list and get productive on your GitHub projects. Happy coding!
Sam Basu is a technologist, author, speaker, Microsoft MVP, gadget-lover and Progress Developer Advocate for Telerik products. With a long developer background, he now spends much of his time advocating modern web/mobile/cloud development platforms on Microsoft/Telerik technology stacks. His spare times call for travel, fast cars, cricket and culinary adventures with the family. You can find him on the internet.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required