0% found this document useful (0 votes)
42 views11 pages

Git Init : Git Clone : Git Add : Git Add .: Git Commit - M : Git Commit - Am : Git Commit - Amend

This document provides summaries of common Git commands for initializing and cloning repositories, staging and committing changes, viewing the status and history of a repository, branching and merging, managing remotes, stashing changes, and more. It explains what each command does at a high level and provides some examples of usage.

Uploaded by

singhdev200311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views11 pages

Git Init : Git Clone : Git Add : Git Add .: Git Commit - M : Git Commit - Am : Git Commit - Amend

This document provides summaries of common Git commands for initializing and cloning repositories, staging and committing changes, viewing the status and history of a repository, branching and merging, managing remotes, stashing changes, and more. It explains what each command does at a high level and provides some examples of usage.

Uploaded by

singhdev200311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

git init <dir>: Initialize git repository

git clone <url>: Clone git repository

git add <file>: Stage file

git add .: Stage all files

git commit -m <commit-msg>: Commit all staged files

git commit -am <commit-msg>: Commit and staged all files

git commit –amend: Modify the most recent commit, change latest log message
git add -> git commit | forget something | git commit –amend, do forget things,
git add, edit and save the commit msg , git commit --amend --no-edit

git status: Displays the state of the working directory and the staging area
git diff: Show changes to unstaged file
git blame <file>: Shows the commit and author information for each line of a file.
git blame -L <start>,<end> <file>: Shows line-by-line commit and author
information for a specific range of lines in a file.
git reset: Undo local changes to the state of a Git repo
git revert: Forward-moving undo operation that offers a safe method of undoing
changes

git reset –soft <older commit id>


git reset HEAD <file>: To Un-staged a file
git restore <file>: To unmodified a file
OR
git reset –hard <older commit id>
Git reset --soft

• It moves the branch pointer to the specified commit, but it keeps the changes in your working
directory and staging area.
• This mode is useful if you want to undo a commit but keep the changes available for further
modifications or if you want to recommit the changes with some adjustments.
• After using "--soft", you can modify the files and create a new commit.

Git reset --hard

• On the other hand, "git reset --hard <commit>" moves the branch pointer to the specified
commit and discards any changes in the working directory and staging area.
• This mode is more destructive because it permanently removes the changes made after the
specified commit. Make sure you have a backup of any important changes before using "--
hard".
• "--hard" is useful when you want to completely undo the commits and start fresh from a specific
point in history.
git log: Review and read a history of everything that happens to a repository
git log --graph: Shows a graphical representation of the commit history.
git reflog: Shows a log of all reference updates, including branch checkouts and
commit changes.
git reflog show <ref>: Shows the log of a specific reference, such as a branch or
HEAD.
git reflog delete <ref>: Deletes the reference from the reflog.
git show-ref: Displays references (branches, tags, etc.) in a Git repository.
git show-branch: Displays the relationship between branches and their commits.
git config --global alias.<alias-name> <git-command>: Creates an alias for a
frequently used Git command.

git config –global user.name=“pranjal”


git config –global user.email=“”
git clean -n -d: Shows a list of untracked directories and files that will be removed

with "git clean -f -d".

Git clean –f : Removed untracked files

git archive <commit> --output=<file>: Creates a tar or zip archive of a specific

commit.

git mv <source> <destination>: Moves or renames a file or directory while

retaining its history.


git remote -v: View remote repository

git remote add <remote-name> <url>: Add remote repository

git remote remove <remote-name>: Remove remote repository

git remote rename <old-remote-name> <new-remote-name>: Rename remote

repository
git push <remote-name> <branch-name>: Upload local git repo to remote

repository

git fetch <remote-name> <branch-name>: Download contents from a remote

repository to local git

git pull <remote-name> <branch-name>: Download contents from a remote

repository and immediately update the local repository


git branch: List all branches

git branch <new-branch-name>: Create new branch

git checkout <branch>: Switch to branch

git checkout -b <new-branch-name>: Create and switch to new branch

git branch -d <branch-name>: Delete branch


git merge <branch-name>: Merge two branches

git rebase <branch-name>: Rebase two branches


git stash: Takes uncommitted changes (both staged and unstaged), saves them
away for later use, and then reverts them from your working copy.
git stash save <comment>: Save stash
git stash list: List all stash
git stash apply: Apply recent stash
git stash apply stash@{1}: Apply stash id 1
git stash show stash@{1}: Show stash id 1
git stash drop stash@{1}: Drop stash id 1
git stash clear: Clear all stashes

You might also like