Git is a distributed version control system that tracks versions of files. It’s shell (git bash) is built as a linux based command line tool.
git status
git init
git add .
git add --a
git add <filename>
git -h
git rm --cached <filename>
git commit -m "message"
git log
rm -rf .git
pwd --> present working directory ls --> list cd --> change directory touch --> to create a file in the repo
.gitignore is a file in which the file names included in it get ignored by git. It ignores blank folders by default.
*.txt # ignores all files with this extension/name
/folder # ignores all folderes and subfolders of this name
git clone <link>
# between working directory and staged area
git diff
# between staged area and commit
git diff --staged
git commit -a -m "message"
git stash # Hold changes
git stash apply # Re-apply the changes
git mv <filename> <newname>
git checkout -- <filename>
# For restoring all files
git checkout -f
# For restoring from staged area
git restore --staged -- <filename>
git generate patch/changes
git diff > changes.patch
apply the diff
git apply changes.patch
It is the remote repository where your files are stored with git. (Like github or gitlab)
# view remote repo name
git remote
# Add the remote repo link to local
git remote add <name> <url>
# View push and pull commands
git remote -v
# Push changes
git push -u <remote_name> <branch>
# Pull changes
git pull
Create alias / shortcut
git config --global alias.<shortcut> <value>
Eg:
git config --global user.username gowtham4545
List braches
git branch
Create Branch
git checkout -b <branch_name>
switch branches
git checkout <branch_name>
Merge branch to master
git merge <branch_name>
Delete branch
git branch -d <name>
Setting new branch to the remote/upstream
git branch --set-upstream-to=origin/<branch_name> <local_branch_name>
Compare branches
git diff <branch1>..<branch2>
Revert the commits
git revert [commit_id]
The git revert command reverts a particular commit, i.e., undoes the commit you made to remove the changes from the master branch.
Note: The git revert command doesn’t remove the commit from commit history. It only adds a new commit specifying that it has reverted the specified commit.</i>
git reset
The git reset command permanently takes you back to a certain point in development. All the files and changes added after that point in time are unstaged if you want to re-add them.
A CheatSheet published by Digital Ocean on a HacktoberFest Event.