Git is a distributed version control system that helps developers collaborate on projects of any size.
Linus Torvalds, the developer of the Linux kernel, created Git in 2005 to control Linux kernel development.
What is a distributed version control system?
A distributed version control system is a system that helps you keep track of changes made to your project files.
This change history resides on your local computer and allows you to easily revert to a previous version of your project if something goes wrong.
Git makes collaboration easy. All team members can keep a full backup of the repositories they are working on on their local computer. They can securely store the repository in one place thanks to an external server such as BitBucket, GitHub or GitLab.
This way, different team members can copy it locally and everyone has a clear view of all changes made by the entire team.
Git has many different commands you can use. And I've found that these fifty are the ones I use the most (and therefore the most useful to remember).
So I wrote them and thought it would be nice to share them with the community. I hope they are useful - Enjoy.
To verify the Git configuration:
The following command returns a list of information about your Git configuration, including username and email:
git config -l
To set your Git username:
You can set your username with the following command:
git config --global user.name "Fabio"
To configure your Git user email:
With this command you can set the user's email address that you will use in your commits.
git config --global user.email "registries@fabiopacifici.com"
To cache your Git credentials:
You can cache your credentials so you don't have to enter them every time. Just use this command:
git config --credencial global.helper-Cache
To initialize a Git repository:
It all starts here. The first step is to initialize a new Git repository locally at the root of your project. You can do this with the following command:
start git
To add a file to the staging area in Git:
The following command adds a file to the staging area. just replaceFile name_here
with the name of the file you want to add to the staging area.
git add filename_here
How to add all files in staging area in Git
If you want to add all your project files to the staging area, you can use a wildcard.
and each file will be added for you.
add git
How to only add specific files to the staging area in Git
You can use the asterisk in the following command to place all files starting with "fil" in the staging area.
git add file *
To check the status of a repository in Git:
This command displays the status of the current repository, including staged, unstaged, and untracked files.
Git-Status
Committing editor changes to Git:
This command opens a text editor in the terminal where you can type a complete confirmation message.
A confirmation message consists of a brief summary of changes, a blank line, and a full description of subsequent changes.
git cometer
To commit changes with a message in Git:
You can add a confirmation message without opening Notepad. With this command, you can only provide a brief summary of your confirmation message.
git commit -m "your commit message here"
To make changes (and bypass the staging area) in Git:
You can add and commit tracked files with a single command using the -a and -m options.
git commit -a -m "Commit message here"
To view your commit history in Git:
This command displays the commit history of the current repository:
Git registration
To view your commit history, including changes in Git:
This command shows the commit history, including all files and their changes:
git log -p
To view a specific commit in Git:
This command displays a specific confirmation.
Replace commit-id with the commit ID found in the commit record after the word commit.
git displays the commit ID
To view non-Git log statistics:
This command causes the git log to show some statistics about the changes on each commit, including changed lines and filenames.
git log --stat
Here's how to see the changes made before committing them to Git with "diff":
You can pass a file as a parameter to only show changes to a specific file.git difference
shows only unscaled changes by default.
We can call diff with the- staged
Check to see the changes in stages.
git diffgit diff all_checks.pygit diff --staged
To see the changes with "git add -p":
This command will open a command prompt and ask if you want to make changes or not and will have more options.
git add -p
To remove tracked files from the current working tree in Git:
This command waits for a confirmation message explaining why the file was deleted.
git rm file name
To rename files in Git:
This command deploys the changes and waits for a confirmation message.
git mv old file new file
To ignore files in Git:
To... create.ignore.git
file and confirm.
To undo changes not provided in Git:
git checkout file name
To undo escalated changes in Git:
You can use the -p option flag to specify the changes you want to revert.
git reset HEAD Archivierungsname reset HEAD -p
To change the most recent commit in Git:
git commit --edit
allows you to modify and add changes to the last commit.
git commit --edit
!!Note!!: Patching a patched local commit is great, and you can move it to a shared repository after patching it. However, you should avoid modifying commits that have already been published.
To revert the last commit in Git:
go to redefine
creates a new commit that is the opposite of everything in the given commit.
We can undo the last commit with the parent alias like this:
git reverter HEAD
Prepare to roll back a previous commit no Git:
You can revert a previous commit with your commit ID. This will open Notepad so you can add a confirmation message.
git retorna commit_id_here
To create a new branch in Git:
By default it has one branch, the main branch. With this command you can create a new branch. Git will not change it automatically; You have to do it manually with the following command.
git rama branch_name
To switch to a newly created branch in Git:
If you want to use a different or newly created branch, you can use this command:
git checkout branch_name
To list branches in Git:
You can see all branches created withrama git
Domain. It displays a list of all branches and marks the current branch with an asterisk and highlights it in green.
rama git
With a single command, you can quickly create and switch to a new branch.
git checkout -b branch_name
To delete a branch in Git:
When you're done working on a branch and merged it, you can delete it with the following command:
git branch -d branch_name
To merge two branches in Git:
To merge the history of the industry you are currently in with thebranch name
, you need to use the following command:
git merge branch_name
To view the commit log as a graph in Git:
we can use--Graphic
for the commit log to be displayed as a graph. Also,--on-line
will limit confirmation messages to a single line.
registrar git --graph --oneline
To view the commit log as a graph of all branches in Git:
It does the same as the previous command but for all branches.
git log --graph --oneline --all
To cancel a conflicting merge in Git:
If you want to discard a combination and start over, run the following command:
git merge --abort
How to add a remote repository in Git
This command adds a remote repository to your local repository (just replacehttps://repo_here
with the URL of your remote repository).
Adicionar git remote https://repo_here
To view non-Git remote URLs:
You can view all remote repositories from your local repository with this command:
git remote -v
For more information about a remote repository in Git:
just replaceOrigin
with the name of the command obtained by
Running the command git remote -v.
git Remote-Demo-What
To push changes to a remote repository in Git:
When all your work is ready to be saved to a remote repository, you can commit all your changes with the following command:
git push
To pull changes from a remote repository to Git:
When other team members are working on your repository, you can get the latest changes made to the remote repository with the following command:
pull git
To check the remote branches that Git is tracking:
This command displays the names of all remote branches that Git is tracking for the current repository:
git rama -r
To get changes from remote repositories in Git:
This command pulls changes from a remote repository, but doesn't do a merge to your local branch (because git pull does that for you).
To search for
How to check the current commit log of a remote repository in Git
Commit after commit, Git creates a record. You can find the remote repository log with this command:
git log source/main
To merge a remote repository into your local Git repository:
If the remote repository contains changes that you want to merge into your local repository, this command will do that for you:
git merge fonte/principal
To get content from remote branches into Git without auto-merging:
This allows you to update the remote without merging the content on the
local branches. You can call git merge or git checkout to perform the merge.
Remote-Git-Update
To push a new branch to a remote repository in Git:
If you want to push a branch to a remote repository, you can use the following command. Just remember to add -u to create the upstream branch:
git push -u origin branch_name
To delete a remote branch in Git:
If you no longer need a remote branch, you can remove it with the following command:
git push --delete origem branch_name_here
To use the Git rebase:
You can use to transfer completed work from one branch to anotherGit-RebaseName
.
git rebase branch_name_here
Git rebase can get really tricky if you don't do it right. Before using this command, I recommend that you read the official documentation again.Here
To run the rebase interactively in Git:
You can run git rebase interactively with the -i flag.
It opens Notepad and presents a set of commands you can use.
git rebase -i master# p, pick = use commit# r, reword = use commit but edit commit# e message, edit = use commit but stop changing #s, squash = use commit but with previous merge commit # f, fixup = like "squash" but delete log message for this commit # x, exec = run command (rest of line) with shell # d, drop = delete commit
To force a push request in Git:
This command forces a push request. This is usually fine for pull request branches as no one else should have cloned them.
But this is not something you want to do with public repositories.
git push -f
Diploma
These commands can dramatically improve your productivity in Git. You don't have to remember all of them, which is why I wrote this cheat sheet. Bookmark this page for future reference or print it if you prefer.
Thanks for reading! By the way, I'm Fabio, a full-stack web developer and educator, and a certified expert in IT automation using Python. If you find this cheat sheet helpful, you're sure to find something interesting on my YouTube channel as well. you can applyHere.