Useful Git Commands

 

Git and Version Control

Basic Commands in folder creation

  • To go to a respected named folder πŸ‘‰cd name  
  • To create a new folderπŸ‘‰ mkdir name 
  • List items inside the folder πŸ‘‰ ls
  • To create a new file in the project folderπŸ‘‰ touch name 

Git Commands

  • Initialize Git πŸ‘‰ git init
  • To see the hidden files in project  πŸ‘‰ls -a
  • Check for staging area files πŸ‘‰git status
  • Adding files to staging area πŸ‘‰ git add filename
  • Commit files πŸ‘‰ git commit -m "message"
  • To see the commit log πŸ‘‰ git log
  • To see changes between previous and new files πŸ‘‰ git diff
  • To get the previous version of file  πŸ‘‰ git checkout filename

Remote Repositories (Git Hub)
  • First, create a repository in GitHub ( Public or Private)
  • Get the link from the repository dashboard
  • Add this command in your git bash  πŸ‘‰ git remote add origin "copied link"
  • Push to the repository  πŸ‘‰ git push -u origin master  
    • origin - name of the remote
    • master - name of the branch 

Git Ignore - You can save secret keys,  API's in this file
  • Create git ignore file πŸ‘‰touch .gitignore
  • Then add the files to the .gitignore file in the project structure
Git Cloning
  • Clone a repository from remote repo (GitHub)  πŸ‘‰ git clone "copied URL"
Branching
  • To create new branch  πŸ‘‰ git branch "name"
  • To see all the branches  πŸ‘‰ git branch
  • To switch to a new branch  πŸ‘‰ git checkout "branch name"
  • To delete new branch  πŸ‘‰ git branch -d "branch name"
Merging
  • To merge a branch  πŸ‘‰ git merge "branch name"


Author - Nisansali Nikapotha












Comments