Git commands


Git Commands


1. How to open git in windows?
     After successful installation of git and configuration of git environment open windows command prompt and execute below commands

   git

  if git is installed successfully then it will display list of commands that can used with git.

2. What is the git command to check the version of git.
      
     git --version
  git version 2.16.2.windows.1

     This command will display the current version of git installed.In the above example it shows as            the version of git as 2.16.2.

3. what is the git command to configure global configuration like name and email id?
     
     git config --global user.name "mahesh"
     git config --global user.email "mahesh.k@abc.com"

     The above commands configure git username and email id. These configuration settings are                 applicable to all repositories as they are global.

4. how to change the default git editor in ubuntu?
    
     git config --system core.editor "/bin/nano"

5. How to initialize a folder for git ?
     If we want to save the data in a folder to git repo first we need to initialize the folder so that git recognizes it as git repo and command to do this is
  
    cd gitrepo
    git init .

   In the above commands first we moved to the folder(git repo) and initialized all the data in the folder with . 

6. what is the git command to check the status of git.
    
    git status

   this command will list out all the changes made to the files in the git.If we observe this folder we find a hidden file called .git which contain the info about the repository.

7. how to add files and folder to git repo.
  
    once we added files and folders to git initialized folder we need to update the info to git and the command to do this is with 
   
   cd gitrepo
   git add .

8. How to check changes and commit them to git.
     Once we made changes to the data we need to check whether changes were made to files or not and later we need to commit them so that these changes can be traced. commands to do these are

   git status
   git commit -m "changes made to file"
   git push origin master

9.What is the git command to remove a file in git repo?
 
  git rm text.txt
 git commit -m "file remove" - redundent

10.what is the git command to check the logs?

  git log
 git log --online
 git log -p

11. what is git command to check the changes made to file?

  git log --oneline --file.txt
 git log --author="mahesh"
 git log --grep="edited"

12.what is the git command to clone the repository?

 git clone .

13. what is the command to push changes to master branch ?
  
  git push origin master

generally when multiple users push code to the repo it will create a conjunction. So to avoid this each user changes were maintained separately by creating branches to the code. Once user thinks that every thing is good then he needs to merge branch code with main code and that point of time above command is used.

14. what is the git command to exclude the files?

   Generally there might be some files in repo which are to maintained but are not modified, for example like cookies files and config files. In this situation we can update the info to git so that it will simple ignore the files weather changes were made to those files or not.

cmd to create ignore file.
git config --global core.excludesfiles

cmd to add files to info ignore file
git config --global core.excludesfiles '/etc/gitignore'

or simple add the files info to '/etc/gitignore' file
nano /etc/gitignore
*.out 
 in above cmd all files ending with .out extension will be ignored.

15. How to create a gitignore file locally and push it to repo?
nano .gitignore
*.bak 
git add .
git commit -m "gitignore file created" .gitignore
now even a new file added with .bak extension then it is not traced.

  

Comments

Post a Comment

Popular posts from this blog

Blender Installation in AWS Windows EC2

How to build and deploy project from Bitbucket to AWS Code Deploy

Git Introduction