Saturday, July 11, 2015

Git Tutorials

1. Read Git ebook
2. Install Git GUI clients. (I use SourceTree)
3. Have fun with Git

Note: SourceTree makes you live easier and you don't have to remember git commands.

Create a Repo:
https://help.github.com/articles/create-a-repo/

Must use tool: SourceTree
SourceTree tutorial

Do a Commit: push your code to github

1.  From GitHub create new repo. It will give you a url: www.github.XYZ.MyNewRepo.git
2. Go to the directory you want to push to git; $cd mydirX
$git init
$git add README.md
$git commit -m "first commit"
$git remote add origin https://github.com/AndreSand/gamma-android-app.git
$git push -u origin master

Now go to your new repo and you will see your code in there.

How to Marge Code:

.5 create new folder SOU
1.  Clone team Repo: /SOU$git clone https://github.com/Org/MyApp.git
2.  (Github web) Create fork: https://github.com/xxxx/MyApp.git
3.  $git remote -v 
4.  change pull origin to myFork url $git remote set-url --push origin https://github.com/xx/MyApp.git
5.  open app in AndroidStudio.
6.  make changes, 
a. $git add . (add your files to the git repo)
b. $git commit -m "First commit"

c. $git push origin
7.  make "Pull" request from GitHub fork (website my fork)

8.  merge (website)

Useful Commands:

Remove your uncommitted changes:
$git reset --hard to remove your uncommitted changes
$git pull

Show origin:
$git remote show origin
$git remote -v

Remove origin:
$git remote set-url origin git://new.url.here
OR
$git remote remove origin
$git remote rm origin

Change Fetch URL:
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Remove commits:

$git reset --hard origin/master

 Git log and show code commits:
$git log branch (will return a list of the commits)

$git show #commit_Number#


GIT branch: switching between branches:

Current branch: $git branch

$git fetch
$git checkout test (branch name test)

To fetch a branch, you simply need to:
$git fetch origin
This will fetch all of the remote branches for you. You can see the branches available for checkout with:
 $git branch -v -a
With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:
$git checkout -b test origin/test

Git Log info

Command to print the commit Comment.
$git log --oneline -3
Prints commit# and commit comment


To get more info about the commit you can do $git show (Commit#)
$git show <commit#>


Reference:

http://zackperdue.com/tutorials/super-useful-need-to-know-git-commands
http://www.gitguys.com/topics/temporarily-stashing-your-work
http://stackoverflow.com/questions/16330404/how-to-remove-remote-origin-from-git-repo
https://help.github.com/articles/changing-a-remote-s-url/
http://stackoverflow.com/questions/1783405/checkout-remote-git-branch