Alwyn Mathew     Publication     Talks     Teaching     Blog     Resume

Git

Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows. Best known git as service are probably GitHub and Bitbucket, but many others are available, like GitLab, GerritForge, etc.

Copy git repository to local

git clone <url>

Create a new local repository

git init

Add one or more files to staging

git add <filename>
git add *

Commit changes to head (but not yet to the remote repository)

git commit -m "Commit message"

Send changes to the master branch of your remote repository

git push origin master

Will apply all your yet-to-be-pushed commits on top of the remote tree commits allowing your commits to be straight in a row and without branches

git pull --rebase origin master

List the files you’ve changed and those you still need to add or commit

git status

Take your uncommitted changes (both staged and unstaged), saves them away for later use

git stash

Throws away the (topmost, by default) stash after applying it

git stash pop

Create a new branch and switch to it

git checkout -b <branchname>

Switch from one branch to another

git checkout <branchname>

List all the branches in your repo, and also tell you what branch you’re currently in

git branch

Delete the feature branch

git branch -d <branchname>

Push the branch to your remote repository, so others can use it

git push origin <branchname>

Delete a branch on your remote repository

git push origin :<branchname>

Fetch and merge changes on the remote server to your working directory

git pull origin <branchname>