Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 27, 2021 06:19 am GMT

Git Commands Cheatsheet: Advanced (20 Git Commands Advanced )

If you are working on a project, whether small or large-scale, you need to track every change made within your team space. You can use any software or applications to keep that track, but we will discuss what Git is, how it works, and some advanced Git commands.

What is Git?
Git is an open-source Version Control System that allows you to work within teams in a unique way. You can use a number of commands and functions to work on the project and keep track of the code changes. It will manage all the changed versions of files and directories. As the project expands, the number of tests increases results in changing code with a version number that can be recovered later. It allows the developers and other project members to keep track of- what changes are made, who made those changes, when the changes were made, and why those changes were required.

Git is a distributed version control system commonly used for commercial software development and complete access to every file, directory, and iteration of the project. With Git, you do not have to be connected to the central repository due to which developers can collaborate with the team from anywhere. The main advantage of using Git is its branching capabilities, which are easy to merge.

Working of Git
Git stores everything like files and directories in binary large object forms, which are represented as trees. These trees can contain other trees or large objects along with text files containing information about those files. If a repository transfer contains many files with the same name but different content, it will also get transferred as large objects, which later get expanded to separate files.

Commit object contains the projects complete history; any change to the project has to be committed. This commit object file will contain the information about that change.

Git Advanced commands

  • How to configure the tooling commands
    The below command will set the name of your commit transactions.
    $ git config global user.name [name]
    The below command will set the email to your commit transactions.
    $ git config global user.email [email address]
    How to create Repositories
    The below command will create a new repository with a specified name.
    $ git init [project-name]
    The below command will allow you to download a project and its complete version.
    $ git clone [url]

  • How to refactor the file name
    The below command will delete the file from the working directory and stages the deletion.
    $ git rm [file]
    The below command will allow you to delta the file from the version control but saves it locally.
    $ $ git rm cached [file]
    The below command will change the file name and prepare it for commit.
    $ git mv [file-original] [file-renamed]

  • How to suppress the tracking
    The below command will list all the ignored files within the project.
    $ git ls-files others ignored exclude-standard
    How to shelve and restore incomplete changes
    The below command will temporarily store all the modified tracked files.
    $ git stash
    The below command will restore the most recently stashed file.
    $ git stash pop
    The below command will list all the stashed changesets.
    $ git stash list
    The below command will discard the most recently stashed changeset.
    $ git stash drop
    Commands to erase mistakes
    The below command will undo all the commits but preserve the changes locally.
    $ git reset [commit]
    The below command will discard all the history and changes back to the specific commit.
    $ git reset hard [commit]
    Commands for group changes
    The below command will display all the local branches in the current repository.
    $ git branch
    The below command will allow you to create a new branch.
    $ git branch [branch-name]
    The below command will delete the specified branch.
    $ git branch -d [branch-name]

  • Miscellaneous commands
    The below command will allow you to connect your local repository to the remote server.
    $ git remote add [variable name] [Remote Server Link]

    To Split a subfolder out in a new repository.
    $ git filter-branch --prune-empty --subdirectory-filter master
    To remove untracked files
    $ git clean -f

    To remove untracked files/directories
    $ git clean -fd

    list all files/directories that would be removed
    $ git clean -nfd

    The below command will tar the project files without .git directory.
    $ tar cJf .tar.xz / --exclude-vcs


Original Link: https://dev.to/aashiya123/git-commands-cheatsheet-advanced-20-git-commands-advanced--35i3

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To