20 essential Git commands you should learn

Here are 20 essential Git commands you should learn for effective use on GitHub

Git commands and their Explanations and examples:

  1. git config: This command sets up your Git user name and email, which will be associated with your commits.
  • Example: git config --global user.name "Your Name"
  • Example: git config --global user.email "[email protected]"
  1. git init: Initializes a new Git repository in your current directory.
  • Example: git init (in your project directory)
  1. git clone: Creates a copy of a remote repository (hosted on GitHub) on your local machine.
  • Example: git clone https://github.com/username/repository.git (replace with the specific repo URL)
  1. git add: Adds files to the staging area, which tells Git you want to include them in the next commit.
  • Example: git add filename.txt (add a specific file)
  • Example: git add . (add all modified files)
  1. git commit: Creates a snapshot of the current state of your project with a descriptive message.
  • Example: git commit -m "Added new feature" (commit with message)
  1. git diff: Shows the difference between your working directory and the staging area (uncommitted changes) or between the staging area and the latest commit (committed changes).
  • Example: git diff (shows uncommitted changes)
  • Example: git diff --cached (shows changes staged for commit)
  1. git reset: Used to undo changes in your working directory or staging area.
  • Be cautious! with these kinds of git commands, This can be dangerous if misused.
  1. git status: Shows the current status of your Git repository, including which files are modified, staged, or committed.
  • Example: git status (get an overview of changes)
  1. git rm: Removes files from your project.
  • Example: git rm filename.txt (remove a file)
  • Be cautious! With these kinds of git commands
  1. git log: Shows the commit history of your repository.
  • Example: git log (view all commits)
  1. git show: Shows the details of a specific commit, including the commit message and changes made.
  • Example: git show commit_hash (replace with the actual commit hash)
  1. git tag: Creates a tag, which is a lightweight reference to a specific commit.
  • Example: git tag v1.0.0 HEAD (create a tag named v1.0.0 for the current commit)
  1. git branch: Manages branches in your Git repository. Branches allow you to work on different features or bug fixes independently.
  • Example: git branch new_feature (create a new branch named new_feature)
  • Example: git checkout new_feature (switch to the new_feature branch)
  1. git checkout: Switches between branches in your repository.
  2. git merge: Combines changes from different branches into your current branch.
  • Example: git merge bugfix (merge changes from the bugfix branch)
  1. git remote: Manages remote repositories (like the one on GitHub).
  • Example: git remote add origin https://github.com/username/repository.git (add a remote named origin)
  1. git push: Uploads your local commits to the remote repository on GitHub.
  • Example: git push origin master (push changes to the master branch on the remote repository)
  1. git pull: Downloads changes from the remote repository and merges them into your local branch.
  • Example: git pull origin master (pull changes from the master branch on the remote repository)
  1. git stash: Temporarily saves your uncommitted changes away, allowing you to work on something else and come back to them later.
  • Example: git stash (stash uncommitted changes)
  • Example: git stash pop (apply the most recent stashed changes)
  1. git clean: Removes untracked files from your working directory.
  • Example: git clean -f (remove untracked files with force)

These 20 Git commands provide a solid foundation for working with Git on GitHub. Remember, practice is key! Feel free to experiment with these git commands on a local project to solidify your understanding.

How to digital sign your custom program

Search japan car & vehicle auctions with direct access via our free car auction.