There are no items in your cart
Add More
Add More
Item Details | Price |
---|
Git is a widely used version control system, originally developed by Linus Torvalds to manage the Linux source code. Today, it powers millions of projects across various programming languages. 🚀
Remembering all the Git commands for common tasks can be overwhelming, so we’ve put together this All-in-One Git Cheat Sheet covering both essential and advanced commands. 🚀
#configuring user information used across all local repositories.#set a name that is identifiable for credit when review version historygit config --global user.name “[firstname lastname]”#set an email address that will be associated with each history markergit config --global user.email “[valid email]”#set automatic command line coloring for Git for easy reviewinggit config --global color.ui auto
#create new repository in current directorygit init#add a file as it's ready for your next commit (stage)git add <file>#add all files as they are ready for your next commit (stage)git add .#show modified files in working directory, staged for your next commitgit status#commit your staged content as a new commit snapshotgit commit -m “[descriptive message]”# Create a new connection to a remote repository by giving it name and it's urlgit remote add <remote_name> <remote_url># push your local branch to specified remote.git push <remote_name> <branch_name># Download new changes from the branch_name on the remote.git pull <remote_name> <branch_name>#Display the entire commit history using the default format.git log
#create new repository in current directorygit init#clone a remote repositorygit clone <url>#for example cloning the entire repo locallygit clone https://github.com/CodingBeam/Test Project.git
#show modified files in working directory, staged for your next commitgit status#add a file as it's ready for your next commit (stage)git add <file>#add all files as they are ready for your next commit (stage)git add .#unstage a file while retaining the changes in working directorygit reset <file>#diff of what is changed but not stagedgit diff#diff of what is staged but not yet committedgit diff --staged#commit your staged content as a new commit snapshotgit commit -m “[descriptive message]”
#create a new branch at the current commitgit branch <branch_name>#list your all branches. a '*' will appear next to the currently active branchgit branch#switch to another branch and check it out into your working directory.git checkout#Create and check out a new branch named [branch_name]. above two commands in one.git checkout -b <branch_name>#merge the specified branch’s history into the current onegit merge <branch>
# remove files & path changes#delete the file from project and stage the removal for commitgit rm <file>#change an existing file path and stage the movegit mv <existingpath><newpath>#show all commit logs with indication of any paths that movedgit log --stat -M
#Retrieving updates from another repository and updating local reposgit remote add <alias><url>#fetch down all the branches from that Git remotegit fetch <alias>#merge a remote branch into your current branch to bring it up to dategit merge <alias>/<branch>#Transmit local branch commits to the remote repository branchgit push <alias><branch>
#Rewriting branches, updating commits and clearing history#apply any commits of current branch ahead of specified onegit rebase <branch>#clear staging area, rewrite working tree from specified commitgit reset --hard <commit>
If you’ve accidentally pushed sensitive information (like SECRET_KEY, API_KEY, PASSWORDS, or .env files) to your GitHub repository, simply deleting them won’t remove them from previous commits. Instead of deleting the entire repository, it's best to wipe the commit history to ensure the data is fully removed. 🔒
Manually deleting the .git folder can cause issues in your Git repository. If you want to clear the commit history while keeping your code intact, follow this method instead:
# Check out a temporary branch to hold our commit:git checkout --orphan TEMP_BRANCH# Add all the files to the temporary branch:git add .# Commit the changes:git commit -m "Initial commit"# Delete the old branch (most probably old_branch would be a master branch):git branch -D <old_branch_name># Rename the temporary branch (TEMP_BRANCH) to master:git branch -m master# Finally, force update to our repository:git push -f origin master
I hope this post will help you in your journey. Keep learning!
Yash Gupta
I am passionate about tech and coding. I share expert insights on Test Automation (Selenium, Cypress, Playwright), API Automation, JavaScript, Python, Svelte, Vue.js, ReactJS, Angular, Flutter, and more. Stay updated with the latest trends! 🚀