Important Git Commands

Some of the very basic git command which we use on a daily basis -

"$ git status" - To check the status of project(any file which needs to add or any commit is pending).

"$ git log" - To check all the logs for commits.

"$ git show - -summary" - To check last commit summary without file name.

"$ git show --name-only" - To check last commit with file path(& name).

"$ git add ." - To add any new files to the branch.

"$ git pull origin master" - To fetch all the latest updated code from master branch.

"$ git fetch origin" - To fetch all the created tags.

"$ git commit -m “enter comment here”" - To commit file changes.

"$ git push origin master" - To push changes from local commit to master branch.

"$ git update-index --assume-unchanged <path-to-file>" - To ignore some files to be tracked by git.

"$ clone https://github.com/schacon/simplegit-progit" - To clone(or copy code form server to local) any project from server.

"$ diff HEAD^ HEAD" - Difference with the previous version of committed file.

"$ gitk or $ git show HEAD" - To check last file changes and open in editor.

"git reset --hard origin/repo_name" - This command reset the complete local code base with the last pulled/fetched code.

Note: I have seen people facing the problem of merging the code if two or more then two people are working on the same file. So if you have some code in a file which is already updated and committed by someone else and if you try to take pull you get following message - 
     "Please commit your changes or stash them"
     
     So here we need to use this command which creates a copy of your code changes in local temporary file and remove from the actual file - 
      $ git stash

     Again take a pull from the same repository -
     $ git pull origin brach/repo_name  // By using this command you will be fetching the updated code from main repository

     Now use this command to add your local changes(which was saved in the temporary file) into the updated code/file which we pulled in last step - 
     $ git stash pop
       
      That's it!!! Your local changes are merged with the updated coded which you pulled from server.

No comments:

Post a Comment