Monday 26 December 2016

Git Basic Commands




  1. Create Repository
    1. Git init
  2. Clone Repository
    1. Git clone <repository path”
  3. Add files to repository
    1. Add specific file  
git add <filepath>
    1. Add multipe files git
Git add <file1path> <file2path>
    1. Add all the files
Git add -A
git add .


  1. Adding modified files
    1. Git add -u
  2. Delete files
    1. Delete the file using OS command (rm)
    2. Git add -u
  3. Renaming files
    1. Renaming files using os Command (mv)
    2. Git add -A
  4. Commit changes to staging area
    1. git commit -m “<change log>”
  5. See history
    1. Git log
  6. Difference
    1. Difference between two commits
      1. git diff <commit-6char-sha1>..<commit-6char-sha1>
    2. Difference from current HEAD to previous version
      1. git diff HEAD~1..HEAD
      2. git diff HEAD~1..
  1. Moving working folder to older commit
Git checkout <commit-6char-sha1>
  1. Moving working folder back
Git checkout master
  1. Undo changes
    1. For a particular file
      1. Git checkout <fileName>
    2. For all the changes
      1. git reset --hard
  2. Ignoring file always under working folder
    1. Creating a gitignore file
  3. Graph and one line logs
    1. git log --oneline --graph
  4. Logs by authors and commit messages
    1. git shortlog
    2. git shortlog -sne
  5. Remote  Name
    1. Git remote
    2. git remote -v
  6. Viewing branches
    1. git branch
    2. Remote branches
      1. Git branch -r

  1. Viewing Tags
    1. Git tag
  2. Adding local repository to remote
    1. Git remote add origin https://github.com/shaikkhajaibrahim/GitPractice.git
  3. Fetch changes from remote
    1. git fetch
  4. Merge  changes
    1. git merge origin/master
    2. This leads to fast forward
    3. git commit after git status
  5. Git pull for fetch + merge
  6. Set the upstream branch for pull to work
    1. Git branch --set-upstreamto master=origin/master
  7. Create a tag
    1. git tag v1.0
  8. Pushing tags to remote
    1. Git push --tags
  9. Create local branch
    1. Git checkout -b “branchname”
  10. Commiting a local branch to remote
    1. git push <remote-name> <local-branch-name>:<remote-branch-name>
    2. For subsequent pushes
      1. git push -u <remote-name> <local-branch-name>
  1. Checkout remote branch
    1. Git checkout <remotebranchname>
      1. (git checkout ImportantFix)
  2. Viewing all branches
    1. $ git log --graph  --oneline --all --decorate

4 comments:

  1. Hats off to your presence of mind..I really enjoyed reading your blog. I really appreciate your information which you shared with us.

    Devops Online Training

    ReplyDelete
  2. Sands Casino: Get a $200 Bonus with $50 Free Chip
    You'll also get up to $50 free Chip. The first sign-up 우리 계열 샌즈 카지노 bonus at Sands Casino is worth just $10.

    ReplyDelete