Day 12: Git Cheat Sheet

Day 12: Git Cheat Sheet

·

3 min read

#Day12 of #90DaysofDevops challenge

Click here to view Day 12 Task.

  • git init - Create empty Git repo in the specified directory. Run with no arguments to initialize the current directory as a git repository.

  • git clone <repo> - Clone repo located at <repo> onto local machine.

  • git config --global user.name <name> - Define author name to be used for all commits by the current user.

  • git config --global user.email <email> - Define the author email to be used for all commits by the current user.

  • git add <directory> - Stage all changes in <directory> for the next commit. Replace <directory> with a <file> to change a specific file.

  • git commit -m "<message>"- Commit the staged snapshot, but instead of launching a text editor, use <message> as the commit message.

  • git status - List which files are staged, unstaged, and untracked.

  • git log - Display the entire commit history using the default format.

  • git diff - Show unstaged changes between your index and working directory.

  • git revert <commit> - Create new commit that undoes all of the changes made in <commit>, then apply it to the current branch.

  • git reset <file> - Remove <file> from the staging area, but leave the working directory unchanged. This unstaged a file without overwriting any changes.

  • git rebase <base> - Rebase the current branch onto <base>. <base> can be a commit ID, branch name, a tag, or a relative reference to HEAD.

  • git branch - List all of the branches in your repo. Add a <branch> argument to create a new branch with the name <branch>.

  • git checkout -b <branch> - Create and check out a new branch named <branch>. Drop the -b flag to checkout an existing branch.

  • git branch -d <branch> - Remove branch named <branch> from git.

  • git merge <branch> - Merge <branch> into the current branch.

  • git remote add <name> <url> - Create a new connection to a remote repo. After adding a remote, you can use <name> as a shortcut for <url> in other commands.

  • git pull <remote> - Fetch the specified remote’s copy of the current branch and immediately merge it into the local copy.

  • git fetch - Fetch all the remote branches.

  • git push <remote> <branch> - Push the branch to <remote>, along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.

  • git log --oneline - Condense each commit to a single line.

  • git restore or git checkout - Restore the file from being modified to tracked.

  • git log --merge - It helps to produce the list of commits that are causing the conflict.

  • git reset --mixed - It is used to undo changes to the working directory and staging area.

  • git merge --abort - Helps in exiting the merge process and returning back to the state before the merging branch.

  • git stash - To stash an item.

  • git stash list - To see stashed items list.

  • git stash apply stash@{<list_number>} - To apply stashed items.

  • git stash clear - To clear the stash items.

  • git stash pop - Popping an item from stash.

  • git stash drop - Used to delete a stash from the queue.

Thank you for reading! 🍁

Nidhi