Wednesday, 2 December 2020

Git Basic Commands

  • Create a remote repository using https://github.com or Oracle DCS. 
  • Generate SSH Key. 
    • Go to git bash cmd. 
    • Type   ssh-keygen  and Enter
    • Accept default values. Note down the folder. 
    • Enter Passphrase
    • Go to the folder and list the files.
    •   You will see two files - id_rsa (Private Key) id_rsa.pub (Public Key)
  • To avoid entering ssh password in case if you have given one while creating ssh key. 
    •   Run  Following Command :    eval $(ssh-agent)
    •   Then Run Following Command :  ssh-add ~private_key_path/.ssh/id_rsa
  • Add the public key in the remote server either using console or command. 
  • Get the SSH link from the Git console. 
  • Create a local folder
    • mkdir ICSLocalRepo
    • Go to local folder -  cd ICSLocalRepo
  • Clone remote repository using following commands. This will clone master branch by default. dot at the end will checkout files to current dir. 
    • git clone ssh/http_URL .
    •  Following command will create a new folder and checkout the branch.
      • git clone ssh/http_URL new_dir_name 
  • Clone a specific branch. Example - develop branch. 
    • git clone -b develop ssh/http_URL  . or new_dir_name
  • List  all remote branches. 
    • git branch -a
  • To check the remote repository details.
    •   git remote -v
  • Check the clone status using status command. 
    • git status
  • Command to add files to local repository and push it to stage
    • git add --all 
    • git add .
  • Commit command. 
    • git comit -m "Commit comments"
  • Push the changes to remote repository.
    • git push origin develop
  • Pull the latest files from remote repository. 
    • git pull --all
  • Access a specific branch 
    • git checkout develop
  • Create a new branch from a remote branch. 
    • git checkout -b release-<release-name> origin/develop
  • Push new branch to origin. 
    • git push origin release-<release-name>
  • Merge changes to a branch. This will merge the changes from new_release_branch to develop. 
    • git checkout develop 
    • git merge new_release_branch

No comments:

Post a Comment