Git Cheat Sheet- 20 commands I Use Everyday

0
102

Tracking changes to my software has always been an issue when I start encoding, and the danger of losing files has always been there. But today we have a Git that will help us solve these problems; It offers everything you need to keep your development environment secure and simple. Git is essential for the daily work of any programmer, especially when working in a group. It is widely used in the software business, but understanding all the commands takes time, so keep practicing.

Why Git?

Git is a distributed version control system that helps us keep track of changes we have made to files in our projects.

You can now easily revert to an earlier version of our code if something goes wrong, which is already there on our local computer.

When working as part of a team, git promotes coordination and management. On his local computer, each team member has full access to the code of the repositories. Anyone may see all the upgrades and adjustments. We can use BitBucket, GitHub or GitLab to store all our repositories on one platform. There are a lot of commands in Git, so here are some of the most common commands.

1. How to test your Git configuration:

The git config command is a convenience function used to configure Git configuration values ​​at the global or local project level.

git config -l

2. Define your Git username and email ID:

There are many combinations and options to choose from. These settings are assigned through the Git configuration. Username and username are two important factors.

Name and email address assigned for execution from local computer.

git config --global user.name "Tabassum"
git config --global user.email "tabassum@gmail.com"

3. Git’s Repo Boot:

This command turns a library into an empty Git repository.

git init

4. Add a file to the staging area in Git:

The command below will add a file to the staging area. Just rename filename_here to the file you want to add to the deployment area.

git add filename_here

5. Add all the files in the staging area in Git:

If you want to add all the files in your project to the staging area, you can use a general character. And any file will be added for you.

git add .

6. Make changes to the editor:

Records the change made for the files in a local repository.

git commit

You can add a commitment message without opening the editor. This command allows you to specify only a brief summary for your commitment message.

git commit -m "first commit"

7. See your commitment history:

This command displays the commitment history for the current pool.

git log

8. Git status:

This command returns the current state of the repo. If a file is in the staging area, but is not committed, it appears, with git status.

git status

9. Remove tracked files from the current work tree:

This command expects a commit message that explains why the file was deleted.

git rm filename

10. Rename files:

This command incorporates the changes, then it expects a commit message.

git mv oldfile newfile

11. Create a new branch:

By default, you have one branch, the main branch. With this command, you can create a new branch. Git will not switch to it automatically – you will have to do this manually with the following command.

git branch branch_name

12. Go to the recently created branch:

When you want to use another or newly created industry you can use this command:

git checkout branch_name

13. List of branches:

You can view all the branches created using the git branch command. It will display a list of all branches and will mark the current branch with an asterisk and mark it with green.

git branch

14. Create a branch in Git and move to it immediately:

In one command, you can create and move to a new branch immediately.

git checkout -b branch_name

15. Merger of two branches:

To merge the history of the branch you are currently in with branch_name, you will need to use the command below:

git merge branch_name

16. Add a remote repository in Git:

This command adds a remote repository to your local repository (just replace https: // repo_here With the URL of your remote repo).

git add remote https://repo_here

17. Cloning other databases:

Git clone is a command that allows you to obtain source code from a remote repository (like Github, for example). In other words, Cloning Git keeps an exact copy of the latest version of a project from a repository to your computer.

git clone

18. Attract changes to a remote repository:

You can use the git pull command to receive updates from a remote repository. This command performs both git retrieval and git merge operations, which means that the local changes are updated and updates to remote repositories are published.

git pull 

19. Impulse for changes to a remote database:

After making your changes, the next thing you want to do is send your changes to the remote server. Git push raises your commitments to the remote repository.

git push

Force boost:

git push -f

20. How to use Git rebase:

You can transfer completed work from one industry to another using git-rebase.

git rebase branch_name_here

Summary

There are hundreds of git commands used by programmers, however these are the most commonly used. I hope these commands help you increase your Git productivity.

These commands can dramatically improve your Git productivity. You do not have to remember them all – that’s why I wrote this cheat page. Bookmark this page for future reference or print it if you wish.

Thanks for reading!

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here