• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Git Commands frequently used by me.

Author:- Tushar Sonu Lambole

 //For more details regarding the git refer following link 
http://classic.scottr.org/presentations/git-in-5-minutes/ 

//To init Empty git Repo. Go to the dir of project 
 git init 

 // Add origin of git 
git remote add origin <URL from repo created> 

//Remove origin from git
git remote rm <origin / bitbucket_tushar>

 // create .gitignore file 
//in case of Mac 
 vim .gitignore //For edit mode 
 press i for edit mode 

 //copy paste for unity3D ignore list 

[Ll]ibrary 
[Tt]emp 
*.csproj 
*.pidb 
*.unityproj 
*.sln 
*.userprefs 

 press Esc then :wq 
//to save file 
 press Esc then :q! 
// to exit without save 

 // To comming the code 
git commit -m "First Commit" 

 // To push the code 
git push -u origin master 
git push -u origin <branch name> // Commit to particular branch 

 // create the branch 
git branch <branch name>

 //So we use the checkout command to change branches. 
git checkout <branch name> 

 //The first branch, or main branch, is called "master." 
git checkout master 

//to update local repository to latest commits
git pull

// Display branches of repo
git remote show

// remove all changes on local project and reset to last commit 
git stash

// remove all changes on local project and reset to last commit With Deleting files 
git stash -u

 // reset the code to particular commit point 
git reset --hard <commit code>

//To retrieve new work done by other people. Fetching from a repository grabs all the new remote-tracking branches and tags without merging those changes into your own branches.
git fetch

//If you already have a local repository set up for the desired project, you can grab all the new information by using
git fetch <remote_name>

//Merging combines your local changes with changes made by others.

Typically, you'd merge a remote-tracking branch (i.e., a branch fetched from a remote repository) with your local branch:
git merge <remote_name>/<branch_name>

//“git pull” is a convenient shortcut for completing both “git fetch” and “git merge” in the same command:
git pull <remote_name> <branch_name>


NOTE: Because pull performs a merge on the retrieved changes, you should ensure that your local work is committed before running the pull command. If you run into a merge conflict you cannot resolve, or if you decide to quit the merge, you can use git merge --abort to take the branch back to where it was in before you pulled.


 // remove the git add . files 
 git rm -r --cached . 

 // forcefully push the code 
git push origin <master/branch> --force 

 // delete file from the repository at server, local all commits from everywhere 
//Take Backup of project before executing below command 
 git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch Assets/NGUI/Examples/Atlases/Wooden/ScanAtlas.prefab' --prune-empty --tag-name-filter cat -- --all 

//Easy step to remove the file from repo and local repo 
You should not do "git add". That's all 

 git rm classes/file.txt 
git commit -m"bla bla bla" 
git push 

 //While in your branch you can commit changes that will not be reflected in the master branch. When you're done, or want to 
//push changes to master, switch back to master and use merge. 

git checkout master 
git merge <branch name> 

 //And if you're done with the branch you can delete with the branch command and pass the -d flag. 
git branch -d <branch name> 

 //When you do a git add . and have deleted files, git won’t stage them to be commited (as deleted). Use
 git add -u 

 // Get the history log of all commits done 
 git log --pretty=format:"%h %s" --graph .....

//Get the history/log of commits done
git log -2

* For more details refer link "http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History" *..... 


If you want to check your settings, you can use the following command to list all the settings Git can find at that point:

git config --list

// List down the remotes added
git remote -v



------------------------ Mac Terminal Commands --------------------------------------- 
 ls -a      // listing hidden directories 
 rm -rf <file name>    // remove the file 
 pwd     // get current working directory 
 find / -name <filename>    // to search directory 
 cp <file full path> <new location path with file name and extention> 
 cat <file name with extention>     // to read file 





Contact

Get in touch with me


Adress/Street

B/1, Keshar Gaurav BLD, Gujarathi Baug, Shahapur

Phone number

+(91) 9423026579

Website

http://tusharlambole.blogspot.com/