Git Commands

 Git Commands

  • First make the repository (Name=RepositoryName) on github.
  • Open the terminal and make the new directory (mkdir NewDirectory).

  • Copy your ProjectFolder to this NewDirectory.

  • Change the present work directory to NewDirectory.

Run these commands

  • git init
  • git add ProjectFolderName

  • git commit -m “first commit”

  • git remote add origin https://github.com/YourGithubUsername/RepositoryName.git

  • git push -u origin master

  • For adding already project

    • cd /path/to/my/repo

    • git remote add origin https://xxxx@bitbucket.org/xxxx/sitename.git

    • git add –all {For adding all the files in one go}

    • git commit -m “<commit message>”

    • git push -u origin –all

    • git push -u origin –tags

    Pull the data to merge to local repo

     $ git pull origin master

    If you do not want to merge the upstream changes wit your local repository, run git fetch to fetch the changes and then git merge to merge the changes. git pull is just a combination of fetch and merge.

    If you do not want to merge the upstream changes wit your local repository, run git fetch to fetch the changes and then git merge to merge the changes. git pull is just a combination of fetch and merge.

    For Checking the status of git

    • git status

     Error

    I was trying to upload an existing project the error i was getting was:-

    No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as ‘master’. error: failed to push some refs to ‘git@github.com:painfreepr/<repo>.git

    The Solution is

    git push origin master

    You further check if master branch is created or not as Git won’t commit empty directories. There must be files in the directories first.

    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s