Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 6.7 KB

command.md

File metadata and controls

42 lines (36 loc) · 6.7 KB

Note: Click on 🔗 to see an example.

  • git config --global user.name "<Enter name here>" to set username. 🔗
  • git config --global user.email <email> to set an email. 🔗
  • git config -h to see the help documentation for 'git config' command. 🔗
  • git help <command> to get the help documentation for a specific git command. 🔗
  • cd <file/folder path> to change directory. 🔗
  • git init to initialize a git repository in the current working directory. 🔗
  • git status to check the current state of the repository. 🔗
  • git add <filename> to track a file in the working directory 🔗
  • git rm --cached <filename> to untrack a file in the working directory 🔗

Tip: To ignore a file/folder create a txt file and rename it as .gitignore , then add the files that are to be ignored such as .txt files etc. 🔗

  • git add . to track all the files present in the directory 🔗
  • git commit -m to Commit all the staged changes (To commit means to take a snapshot of the repository at particular point of a time). 🔗
  • git commit -m "<Your Message>" to add a message for a commit directly in the command line 🔗
  • git restore --staged <filename> to remove the changes that were previously staged 🔗
  • git commit -a -m "<message>" to stage all modified and delete files automatically and create a new commit with the specified commit message in a single step. 🔗
  • git rm "<filename>" to delete a file. 🔗
  • git restore "<filename>" to restore a file. 🔗
  • git mv "<oldname>" "<newname"> to rename a file. 🔗
  • git log /git log --oneline to view the commit history of the repository, i.e see all the commit in chronological order. 🔗 🔗
  • git commit -m "<newMessage>" --amend to change the message of recent commit (Using amend command changes the commit ID and hence should not be used in public repositories). 🔗
  • git log -p (-2) to see the commit history along with the actual content changes (patch) introduced in each commit. 🔗
  • git show <commit_ID> to view detailed information about the specified commit, including the commit message and changes introduced. 🔗
  • git rm <filename> to remove a file from both, working directory and git repository.
  • git checkout <filename> to Undo unstaged changes. 🔗
  • git checkout <filename> -p to interactively preview and selectively discard changes within the specified file before restoring it to the state of the last commit.
  • git reset HEAD <filename> to remove files from staging. 🔗
  • git revert HEAD to revert/ rollback to a previous commit. 🔗
  • git branch to see, create and manages all the branches in a repository. 🔗
  • git branch <new-branch-name> to create a new branch. 🔗
  • git checkout <branch-name> to switch to a new created branch. 🔗
  • git checkout -b <branch-name> to create and switch to a new branch. 🔗
  • git branch -s <branch-name> to delete a branch. 🔗
  • git merge <branch-name> to merge a branch. 🔗
  • git merge --abort to abort in case of merge conflicts.
  • git log --graph --oneline to get detailed view about how a merge happened.