Git revisited

  1. git add -u
    • Add all modified files into staging area.
  2. git commit -a
    • Automatically adds all tracked files  to staging area for committing
  3. git diff –staged
    • Diff the content already added to staging area( using git add command )
  4. git remote add <alias> <remote git repo location>
    • Makes a reference to the remote repository with the given name
    • Example: git remote add origin https://github.com/vineel567/project123.git
    • orgin acts as an alias to the remote repository
  5. git remote -v
    • List all remote repositories aliased
    • Example: git remote -v
    • origin  https://github.com/vineel567/project123.git (fetch)
    • origin  https://github.com/vineel567/project123.git (push)
  6. git fetch <remote alias>
    • Fetches the remote repo to local but does not merge on to the current branch, Instead creates a new remote tracking branch
    • git br -a  will show all the remote branches in red color
      • * master
        remotes/origin/master
    • git remote show <remote alias> will show the info of all the remote and local branches with respect to the remote repo.
      • * remote origin
        Fetch URL: https://github.com/vineel567/project123.git
        Push URL: https://github.com/vineel567/project123.git
        HEAD branch: master
        Remote branch:
        master                tracked
        Local ref configured for ‘git push’:
        master pushes to master (local out of date)
  7. git pull <remote alias> <remote branch>
    • Fetches the remote repo to local and also merges onto the current branch, Also creates a new remote tracking branch
    • git br -a  will show all the remote branches in red color
      • * master
      • remotes/origin/master
    • git log will show the detailed commits recreated after the pull
  8. git push <remote alias> <branch>
    • Find a ref that matches <branch> in the source repository (most likely, it would find refs/heads/master), and update the same ref (e.g. refs/heads/master) in <remote alias> repository with it. If <branch> did not exist remotely, it would be created.

References: http://gitref.org/

Leave a comment

Leave a Reply