rama-chitturi / MySolutionHub

0 stars 0 forks source link

Git useful commands #23

Open rama-chitturi opened 3 years ago

rama-chitturi commented 3 years ago
  1. Open Git Bash

  2. To know the Git version

    git --version

  3. To add user Git access

git config --global user.email gituserid.gmail.com (or) git config --global user.name "GitUsernameWithinQuotes" -3.1. Password will be asked by raising a credential input popup after pushing code to remote atlast. -3.2. To change git user need to remove autoset credentails in Control panel-->User accounts-->windows credentails manager"

  1. To add local repository of git 4.1. Open git bash in the project folder (Make a directory using 'cd path' or 'cd -' [for previous path] or 'cd /' - [for into root directory])
    4.2. > git init - use within directory: to start git intilization locally. 4.3. > git add filename (or) > git add * (for all files to add) 4.4. > git commit -m "commiting message" 4.5. > git status - We can check git status anywhere to track.

  2. To add remote repository

    git remote add origin https://URL_of_Remote_repository

    • here, git creates a connector to connect with outside(server) called remote.
    • using above command it create a remote called origin. git -v remote
    • To see the remotes added git remote remove origin
    • To remove origin remote
  3. To push the code

    git push origin master (If you are doing very first push)

    • here, it tells to push the code from master(i.e in local branch) to the remote named Origin(which reflects at remote server- github)
  4. If we want to push changes later with some modification through branch

    git checkout -b branchName

    • Creates a branch with branchName and checkouts to the same
  5. now add and commit files

  6. git push origin branchName

    • This creates a branch on git repo and we can verify and create a pull request and then can merge the pull request to master branch through github portal