Mar 10, 2012

Using GIT

GIT is a distributed version control system. Unlike SVN, which is centralised, each copy of a git project tree contains it's very own repository. This makes it easier to create branches and forks for development without polluting the main code trunk.

  • To start your first local git repository:
    1. Initialise the repository
      git init
    2. Add all the files in the current directory
      git add .
    3. Commit your initial import
      git commit
  • To monitor changes and logs in your code:
      1. View the revision history
        git log
      2. View the file changes in the repository
        git diff
      3. View the changes for a specific revision and file/directory path
        git diff revision path
      4. Summary of the current changes to the repository
        git status
  •  Some house cleaning functions:
      1. To add a file:
        git add file
      2. To remove a file:
        git rm file
      3. To move a file:
        git mv file
      4. To remove all untracked files (such as temporary files used during compilation):
        git clean
  •  Configure your git instance
      1. Change your username
        git config --global user.name "Your Name"
      2. Change your email
        git config --global user.email email@domain.com
  •  Common functions
      1. Clone an existing repository
        git clone url
      2. Fetch the changes from remote master repository
        git fetch
      3. Similar to above, but this command will merge the changes as well
        git pull
      4. Push your changes to a remote repository
        git push url
      5. Commit all your changes to the local repository
        git commit -a
      6. Edit your last commit with latest changes
        git commit --append
      7. Toss away your last commit
        git reset HEAD^
      8. Assign blame for problematic files
        git blame file
  • Tags and branches
      1. Tags a version
        git tag -a name
      2. List tags
        git tag -l
      3. Show the details about a tag
        git show tag
      4. Create a new branch
        git branch branch
      5. Switch to a branch
        git checkout branch
      6. Delete a branch
        git branch -d branch
      7. List all branches
        git branch
      8. Merges a branch to our current working branch
        git merge branch
 References
http://schacon.github.com/git/gittutorial.html
http://gitref.org 

No comments:

Post a Comment

Thanks for contributing!! Try to keep on topic and please avoid flame wars!!