Ubuntu insights, Programming in groovy, java, et als!

Wednesday, November 06, 2013

Fun with Git

Baby steps : 

1) create an account on github
2) create a git repository. Note down the repo URL.

Install git from terminal : 

sudo apt-get install git

Code Upload :
cd Scripts (or any new folder)
git init (local initialization. creates a local .git folder)
mkdir YourProjectDirectory (and add all source files under it).
git add .
git commit (commits the added source files to the local repository)
git remote add origin yourRepoURL (ex: https://github.com/vamsi-emani/pythonscripts.git)
git pull origin master (to sync with remote copy)
git push origin master (commits all the local changes to remote repository)

To delete a directory: 
git rm -r local-directory-name (recursively remove all local directory files)
git commit (commits to local repo)
git push origin master (commits to remote repo)

Checkout a branch : 
git checkout -b dev_temp origin/test
(creates a local branch dev_temp from remote branch named test)

List local branches only :
git branch

List local and remote branches : 
git branch -a

List all commits on all branches that aren't pushed yet
git log --branches --not --remotes

View commits on a branch (lists out the commits with their hashes)
git log dev_temp

View what's in a specific commit 
git log commit-hash

Remove untracked files
git clean -f --dry-run (to know the damage before doing the action)
git clean -f (to actually delete the untracked files)

Remove untracked files and directories
git clean -f -d