Git is the undisputed king of source code management! However, it can be a little daunting for new users, especially as most developers and online guides favour the command line.

Thankfully, there are a set of common commands that cover 80% of my standard workflow.

User Setup

Setting your username and email.

git config --global "<name>"  
git config --global "<email>"  


Initialising your repository, updating the index, record changes and pushing to the remote.

git init  
git add .  
git commit -m "Initial Commit"  
git push origin <branch>  


Clone a repository into a new directory.

git clone <repo_url>  
git clone -b <branch> <repo_url>  
git checkout -b <branch> origin/<branch>  

Remote Setup

Manage set of tracked repositories.

git remote  
git remote add origin <repo_url>  
git remote -v  
git remote rm origin  


Fetch from and integrate with another repository or a local branch.

git pull  
git pull <branch>  
git pull origin <branch>  


Branching is a powerful way to manage your code, I highly recommend following a branching methodology such as Git Flow.

git branch  
git branch <branch>  
git checkout <branch>  
git checkout -b <branch>  
git branch -m <newname>  
git branch -d <branch>  


Join two or more development histories together.

git merge <branch>  


Tag specific points in history.

git tag TAG_01  
git push origin --tags  

Lines of Code

Show lines of code in the active branch.

git ls-files | xargs wc -l  

Ignored Files

Show files that are ignored by Git.

git status --ignored  

Remove .DS_Store

If you work on a Mac, you will probably also have pesky .DS_Store files cluttering up your repository. To remove them run the following command (don’t forget to also add .DS_Store to your “.gitignore” file.

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch  

GitHub Chunked Issue

If you recieve the error “POST git-receive-pack (chunked)” when pushing code to GitHub or the push simply fails (hangs), run the following command. This should resolve a known chuncked encoding bug in Git, when using HTTPS.

git config http.postBuffer 524288000

If you’re unsure about any of these commands, I suggest you head over to the official Git documentation or Git online training.