GitHub - GIT CHEAT SHEET
Git :- Imagine you have a big box of your favorite toys. Git is like a magic spell book that helps you keep track of every toy you put in the box and every change you make to them.
GitHub :- GitHub is like a big playground where you can share your toys with friends. They can see what toys you have, they can play with them, and even help you make them better by adding new things or fixing broken parts
Basic Git commands:
git init : This command initializes empty git repository. In simple terms it converts your file system directory to a git repository.
git config --global user.name "Your username ex. whitehats6950" : This command is used to set a name and this helps when reviewing the version history.
git config --global user.email "Your email ex. whitehats6950@mailinator.com" : This command is used to set a email and this helps when reviewing the version history.
git clone [repository URL] : This will make a copy of your project from remote repository to your local machine.
git remote add origin [repository URL] : This will connect your local repo with the remote repository which you have created on git hub.
git status : This command will show the status of your git repository for example what all files have been tracked, untracked on git.
git add [filename] : This command will add your file into staging area means it will now tracked your file for version controlling.
git commit -m "commit message" : This will commit your tracked changes into local git repo.
git push origin [branch name Ex. master] : This command will move all your local system changes to remote repository.
git log : This will show the commit history.
git log --oneline : This will show the commit history in pretty format.
git restore --staged [filename] : This command will untracked the file if it is tracked on git.
git pull origin [branch name ex.] : This command pull all the changes from remote branch to local current branch.
git branch [branch name] : This command will create a new branch.
git branch : This command will show all the branches and will show your current active branch.
git checkout -b [branch name] : This command will create a new branch and will switch into it.
git switch [branch name] : This command will switch to the specified branch provided by you.
git revert [commit id] : This will undo your changes.
git reset [commit id] : This will reset your commited changes but it will preserve in your local system.
git reset --Hard [commit id] : This will reset your commited changes and the changes will not preserved in your local system.(P.S use this command cautiously).
git rebase [branch name] : This command will maintain a linear commit history and this is used to bring the other branches changes into the current branch.
git merge [branch name] : This command will merge the changes of specified branch into the current active branch.
git stash : This command is used to temporarily saved your changes before it is commited.
git stash pop : This command is used to retrieve stashed changes.
git branch -d [branch name] : This command deletes the specified branch.
git fetch : Fetch down all the branches from that Git remote
git cherry-pick [commit id] : This will add the commited changes into the current active branch
Happy Learning :)
Subscribe to my newsletter
Read articles from Harshal Kamble directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by