Amit Dhamu

Writes Code

Git Commands

// Initialise empty git repo
git init

// Add all files to staging area
git add .

// Clone repo
git clone git@bitbucket.org:user/repo.git #SSH
git clone https://bitbucket.org/user/repo.git #HTTPS

// Commit all staged files without editor
git commit -am "My commit message"

// Commit all staged files with editor
git commit -a

// Create a new branch 
git branch new_branch

// Switch to branch
git checkout new_branch

// Create a new branch and switch to it (shorthand)
git checkout -b new_branch

// Delete a branch
git branch -d new_branch

// Merge branch2 into branch1
git checkout branch1
git merge branch2

// Add remote tracking origin
git remote add origin ssh://git@bitbucket.org/user/test.git

// Push to remote for the first time (new local repo)
git push -u origin master

// Push
git push

// Pull changes
git pull

// See what's changed
git log
// OR
git whatchanged

// Who changed what and when for a file
git blame file.php

// See uncommitted or unadded files
git status

// Show diff for all files
git diff

// Search
git grep "Search term"

// Revert last commit
git revert HEAD

// Revert to specific commit
git revert $commit_id

// Reset to last committed state
git reset --hard

// Tag
git tag v1.0


git / github / bitbucket / version control / vcs

← UNIX Commands Vim Commands →