Tuesday, October 10, 2017

Git - Most Useful/Commonly Used Git commands

  1.  It is a distributed version control repository and it has source code management (SCM) functionality.
  2. It offers more features like bug tracking, task management, markdown format’s, graphs, email notifications, Gist code snippets and wiki for every project
  3. It offers both private and public repositories on same account.
  4. Un-track the specific files/folders by creating a file with “.gitignore”
Git Commands 
  • git init 
          Initialize current directory as a Git Repository
  • git clone <url> 
          download complete repository from the specified git url
  • git status 
          It shows all the files which are added/modified and ready to commit
  • git add <filename> (or) git add . 
          Either add single file or complete folder directory to the staging area to track the changes
  • git commit –m “<commit message>” 
          commit changes to staging repository
  • git remote add <alias> <git-url> 
          add GitURL as alias name. So it can be used easily for push and pull content
  • git remote remove <remote alias name> 
          delete remote alias name of Git-URL
  • git remote set-url <remote alias name> <new-git-url> 
          update remote alias name with new Git-URL
  • git push –u <remote –alias-name> <branchname> 
         push/move the content to remote git url with specific branch. Default could be <master> branch
  • git push –u <remote –alias-name> <branchname>:<newbranch> 
         creates new remote branch and push/move the content to that new branch.
  • git pull <remote-alias-name> <branchname> 
          fetch and merge all the files from the specified git remote repository/branch
  • git pull <remote-alias-name> <branchname> --allow-unrelated-histories 
          merge unrelated histories to local branch
  • git checkout –b <new-branch-name> 
          create new duplicate branch from master branch
  • git branch 
          It display all the available branches and * indicates current active branch
  • git checkout <branch-name> 
          Switching between the branches
  • git branch –d <branch-name> 
          delete the specified branch name
  • git stash 
          discard all local changes, but save them for later use
  • git checkout -- <file>
          discard local changes permanently for the given file and updated with new data from Git Repo
  • git reset --hard
          discard all local changes permanently 

Regular Branch Create/Push Steps :

  1. Go to command prompt ( ex:  D:\abc-development> )
  2. Create branch ( i.e. abc-task1 ) from “Develop” remote repo
>git checkout -b  abc-task1 origin develop
  1. Make required changes in abc-task1
  2. Adding all modifications to local repo
         >git add .
  1. Commit/stage all modifications to local repo
         > git commit -m “first commit”
  1. Push all changes to remote repo
          >git push -u origin abc-task1


Feature Branch Create/Push Steps :

  1. Go to command prompt ( ex:  D:\abc-development> )
  2. Create branch ( i.e. abc-task1 ) from “feature/abc-task1” remote repo
>git checkout -b  abc-task1 origin/feature/abc-task1
  1. Make required changes in abc-task1
  2. Adding all modifications to local repo
          >git add .
  1. Commit/stage all modifications to local repo
          > git commit -m “first commit”
  1. Push all changes to remote repo

         >git push origin HEAD:feature/abc-task1


Happy Coding :)

No comments:

Post a Comment