Top Git Commands

List of git commands

  • git config: This command sets the author name and email address respectively to be used with your commits.

git config --global user.name "Bob Smith"
git config --global user.email bob@example.com
  • git init: This command is used to start a new repository.

git init [repository name]
    • git cloneCreate a working copy of a local repository:
    git clone /path/to/repository
    i.e git clone https://github.com/narottamsingh/spring_boot_multiple_database.git
    // for a remote server use
    git clone username@host:/path/to/repository
        • git add: Add one or more files to staging (index):
        git add <filename> // single file add

        git add * // all file add
              • git commit: Commit changes to head
              git commit -m "Commit message"
              • git commit: This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.

              git commit -a  
              • git diff: This command shows the file differences which are not yet staged.
              git diff
                      • git diff -staged: This command shows the differences between the files in the staging area and the latest version present.
                      git diff -staged
                      • git diff [first branch] [second branch]: This command shows the differences between the two branches.
                      git diff [first branch] [second branch]
                      • git reset
                      //This command unstages the file, but it preserves the file contents.

                      git reset {filename}

                      //This command discards all history and goes back to the specified commit.
                      git reset --hard {filename}

                      //Instead, to drop all your local changes and commits,
                      // fetch the latest history from the server and point your local master branch at it

                      git reset --hard origin/master
                              • git status: List the files you've changed and those you still need to add or commit
                              git status
                                      • git rm: This command deletes the file from your working directory.
                                      git rm <filename>

                                      git add * // all file add
                                              • git log: This command is used to list the version history for the current branch
                                              git log
                                                      • git show: This command shows the metadata and content changes of the specified commit
                                                      git show [commit]
                                                              • git tag: This command is used to give tags to the specified commit
                                                              git tag [commit]

                                                              git add * // all file add
                                                                      • git branch: This command lists all the local branches in the current repository
                                                                      git branch
                                                                              • git branch creates: This command used to create local branches.
                                                                              git branch [branchName]
                                                                                        • git branch delete: This command used to delete the branch
                                                                                        git branch -d [branchName]
                                                                                                    • git checkout: This command is used to switch from one branch to another
                                                                                                    git checkout [branchName]
                                                                                                            • git checkout and create: This command is used to switch from one branch to a newly created branch
                                                                                                            git checkout -b [branchName]
                                                                                                                      • git merge: To merge a different branch into your active branch
                                                                                                                      git merge [branchName]
                                                                                                                              • git remote: If you haven't connected your local repository to a remote server, add the server to be able to push to it
                                                                                                                              git remote add origin <server>
                                                                                                                              git remote add origin https://github.com/narottamsingh/spring_boot_multiple_database.git
                                                                                                                                      • git push: This command sends the committed changes of the master branch to your remote repository
                                                                                                                                      git push -u origin [branchname]
                                                                                                                                      git push origin master
                                                                                                                                      git push --all origin // push all local repository to remote
                                                                                                                                              • git pull: Fetch and merge changes on the remote server to your working directory:
                                                                                                                                              git pull https://github.com/narottamsingh/spring_boot_multiple_database.git
                                                                                                                                                      • git stash: This command temporarily stores all the modified tracked files. This command used when we want to another work and keep existing.
                                                                                                                                                      git stash save  // to store

                                                                                                                                                      git stash pop // restores the most recently stashed files.

                                                                                                                                                      git stash list // list all stashed changes

                                                                                                                                                      git stash drop //  discards the most recently stashed changeses.

                                                                                                                                                              No comments:

                                                                                                                                                              Post a Comment