Git Cheat sheet
Hiiee!!! Alfiyabanu Bhojani here... I would like to be a part of an organization where I could use and enhance my knowledge and talent for the development of both the organization and myself. Skilled in HTML & CSS, Javascript. With excellent communication skills and always ready to learn new skills and a good team player. Currently I am discovering Full Stack Javascript by Hitesh Choudhary sir...
A Git is a developer tools used for tracking code changes, tracking who made changes and Coding collaboration. It is a popular version control system. It was created by Linus Torvalds in 2005 and has been maintained by Junio Hamano.
Most Common Git commands
1. git clone:- Git clone command is used for downloading the latest version of a project and copying it to the selected location.
i.e. git clone <repository url>
For clone a specific branch, we can use
i.e git clone <respository url> -b<branch name>
2. git config:- Git config command is used to set the author name and email address respectively to be used with commits.
i.e git config --global user.name "Alfiya"
i.e git config --global user.name"alfiya12@gmail.com"
3. git init:- Git init command is used to start a new repository.
i.e git init[repository name]
4. git add:- Git add command used to adds a file to the staging area.
i.e git add[file]
- git add * :- Git add * command used to adds one or more file to the staging area.
i.e git add *
5. git commit:- Git commit command used to snapshot the file permanently in the history.
i.e git commit -m "[Type in the commit message]"
- git commit -a:- Git commit -a command commits any files that you've added with the git add command and also commits any files that you've changed since them.
i.e git commit -a
6. git diff:- Git diff command shows the file differences which are not yet staged.
i.e git diff
- git diff -staged:- This command shows the difference between the files in the staging area and the latest persent
i.e git diff -staged
- git diff [first branch][second branch]:- This command shows the differences between two branches mentioned.
i.e git diff [first branch][second branch]
7. git reset :-
- git reset [file]:- This command unstages the file, but it preserves the file content.
i.e git reset [file]
- git reset [commit]:- This command does not change all the commits after the specified commit after the specified commit and preserves the changes locally.
i.e git reset [commit]
- git reset -hard[commit]:- This command discards all history and goes back to the specified commit.
i.e git reset -hard[commit]
8. git status:- Git status commands lists all the files that have to be committed.
i.e git status
9. git rm:- Git rm command will remove/ delete the file from your working directory and stages the deletion.
i.e git rm
10. git log:- Git log command is used to list the history for the current branch.
i.e git log
- git log -follow[file]:- This command is used to lists history for a file, including the remaining of files also.
i.e git log -follow[file]
12. git show:- This command shows the metadata and content changes of the specified commit.
i.e git show [commit]
13. git tag:- This command is used to give tags to the specified commit.
i.e git tag [commitID]
14. git branch:- Git branch command lists all the local branches in the current repository.
i.e git branch
- git branch[branch name]:- This command is used to creates a new branch.
i.e git branch [branch name]
- git branch -d[branch name]:- This command is used to deletes the feature branch.
i.e git branch -d [branch name]
15. git checkout:-
- git checkout [branch name]:- This command is used to switch from one branch to another.
i.e git checkout [branch name]
- git checkout -b [branch name]:- This command is used to creates a new branch and also switches to it .
i.e git checkout -b [branch name]
16. git merge:- This command used to merges the specified branch's into the current branch.
i.e git merge [branch name]
17. git remote:- This command is used to connect to your local repository to the remote server.
i.e ` git remote add [variable name][Remote Server Link]
18. git push:- This command sends the committed changes of master branch to your repository.
i.e git push [variable name] master
- git push [variable name] [branch]:- This command sends the branch commits to your remote repository.
i.e git push [variable name] [branch]
- git push -all [variable name]:- This command pushes all branches to your remote repository.
i.e git push -all [variable name]
19. git pull:- This command fetches and merges changes on the remote server to your working directory.
i.e git pull [Repository Link]
20. git stash:- This command temporarily stores all the modified tracked files.
i.e git stash save
- git stash pop:- This command restores the recently stashed files.
i.e git stash pop
- git stash drop:- This command discards the recently stashed files.
i.e git stach drop
For more details, click on above link.
