Friday, February 17, 2017

Git Cheat Shit

Create Repo
## git repo is created bitbucketi
## to put your project on local to remote server
git init
git remote add origin [user name]@[git url]
git add .
git commit -m "message for 1st commit"
git push -u origin master

Make Commit
## to make commit your updates
git status
git add --all
git commit -m "Love you!"
git push -u origin master
Undo git add
## unstage change before commit
git status
git reset file_name.asd
git status

Undo git add
## unstage change before commit
git status
git reset file_name.asd

Clone
## to take the repo
git clone [user name]@[git url]

Update Project from Remote Repo
## to update 
git remote update
git status
git pull

Clean Local Changes and Update
## overwrite local changes
git fetch
git reset --hard origin/master

Show Latest Version of Only Single File
## show head version of file
git show HEAD^:admin/[file name]

Show Difference Between Local File and Latest Version
## to see difference
git diff HEAD^^ [file name]

Return Lastest Commit 
git reset --hard HEAD^

Show Branches 
## show available branches
git branch -a

## show remote branches
git branch -r

Create Branch
## create branch locally
git branch [new branch name]

Switch to Branch
## switch to branch to branch
## 1st you must 
git checkout master
git checkout [branch name]

Push new Commit to Branch
git add .
git commit -m “Love me!”
git push origin 
Create new branch on current existing project
## when you started project and you decide to make it new branch
git checkout -b 
git add 
git commit -m "i decide this code to be new branch"
git push origin

Merge Branch with Master
## switch to master
git checkout master 
git merge 

## commit if works
git push origin master

Delete Branch Locally
git branch -d 

Delete Branch Remotely
git push origin --delete 

Pull Master Branch over New Branch
git pull origin master

Merge with Master Branch with Conflict
git checkout master
git merge 
    ## command output :
    Auto-merging index.html CONFLICT (content): Merge conflict in some-conflict-file 
    Automatic merge failed; fix conflicts and then commit the result.
git checkout master git merge ## fix the issues with meld git mergetool --tool meld git commit git origin master
 
Revert to Previous Commit on Remote Repo
## use soft to keep the mistaken commit
git reset --hard 
git commit -m 'restoring the mistaken commit to master branch'
git push -u origin master
 
Revert to Previous Commit on Remote Repo
## use soft to keep the mistaken commit
git reset --hard git commit -m 'restoring the mistaken commit to master branch'
git push -u origin master
 
Clean the local Changes
## show files to be deleted
git clean -n 

## say good bye to your files
git clean -f
 
## aand directories
git clean -f -d 

## clean ignored files
git clean -f -X

No comments: