Git Commands

Git Commands:
  • Install Git:
    sudo apt-get install git

  • Edit User Name and EMail:
    git config --global user.name "Enter Name Here" git config --global user.email "email.org"

  • Check your user name and email:
    git config user.name
    > Enter Name Here
    git config user.email
    > email.org

    Alternative:
    git config --list
    > user.email=Enter Name Here
    user.name=email.org

  • Create new local repository, example for perlscripts:
    git init perlscripts
    cd into new directory
    cd perlscripts

    Create Read me file:
    vim README.txt
    Enter some text and save

    Eiter create new file locally or copy in an existing file to the local respository
    Now with file local add README.txt and file to repository, example
    git add README.txt
    git add reversepicturerename.pl

    Now commit changes to local repository:
    git commit -m "Add Some meaningful message of the commit"

    Now push to github with https url https://github.com//.git, example:
    git remote add origin https://github.com/renedjenkins/perlscripts.git
    git push origin master

    Same but with ssh:
    git remote add origin git.com:renedjenkins/perlscripts.git
    git push origin master

  • Remember its important to first run a pull from the repository if multiple people are working on same project:
    git pull origin master

  • How to list the status of a git repository:
    git status
    Example output:
    On branch master
    Your branch is up to date with 'origin/master'.
    Changes not staged for commit:
    (use "git add ..." to update what will be committed)
    (use "git checkout -- ..." to discard changes in working directory)

    modified: README.txt

    Untracked files:
    (use "git add ..." to include in what will be committed)
    ... (list of file)

  • How to add all files in directory to staging area for commit
    git add -A

  • To see current changes in files that are tracked in repository
    git diff

  • Check which branch you are working on
    git branch

  • Reference:
    Installing and using Git and GitHub on Ubuntu: A beginner's guide

    Git Tutorial for Beginners: Command-Line Fundamentals
  • How to commit in eclipse:
    1. Create GitHub account and SignIn
    2. Start a Project = Create a repository
    3. Start Eclipse
    4. Goto Perspective - Git Repositories and click on Add Git Repo
    5. Create a project in Eclipse
    6. Do a right click on Project - Team - Share - Add to git repo
    7. Commit and Push the project to the repo
    8. Commit and Push every change to the repo