![]() To create a Git branch named “feature”, use: git branch feature Here’s the basic git branch usage to list all existing branches: git branch Use this command to manage branches in your Git repository. For example, enter this command to set your email address for commits: git config -global user.email –global flag applies the configurations universally, impacting your local repository. This command configures various aspects of Git, including user information and preferences. To move a file to a different directory, enter: git mv file1.txt new_directory/ Here’s the Git command to rename a file: git mv file1.txt file2.txt Use this command to rename and move files within your working directory. This command removes files from your working directory and stages the removal for the next commit. ![]() To compare changes between two commits, use the following: git diff commit1 commit2 For example, this git diff usage identifies the differences in a specific file: git diff file1.txt This command lets you compare changes between your working directory and the most recent commit. The basic git log usage lets you view a chronological list of commit history: git log This command displays valuable insights into your files’ modifications and staging status. Use this command to create a commit message for the changes, making them part of your project’s history: git commit -m "Add new feature" This command is used to stage file changes, preparing them for the next commit: git add file1.txt ![]() To create a new repository while specifying the project’s name, use the following command: git init Here’s the basic git init usage: git init This command initiates a new Git repository within a directory. Let’s explore some essential Git commands and their functionalities. If you prefer a graphical user interface (GUI) for writing Git commands, consider using one of the best Git GUI clients. Fortunately, this section will guide you through the most frequently used Git commands in the command line interface (CLI) tool. Or sudo dnf install git Most Commonly Used Git Commandsįor some users, Git may have a steep learning curve. If you’re using a Hostinger VPS hosting plan, you can install Git directly to your server by typing one of the commands below depending on your installed OS:įor Debian-based distributions, including Ubuntu: sudo apt install gitįor Fedora-based distributions, such as CentOS: sudo yum install git It is available for Linux or Unix, Windows, and macOS. Git can be downloaded from its official site. After you commit your modifications, a snapshot of the changes will be saved in the directory. Then, the changes are indexed in the staging area. The working directory is where you add, delete, and edit files. Sometimes you realise you’re in a bit too deep on this merge conflict - in which case you can undo it by running git merge -abort.A Git project consists of three major sections: the working directory, the staging area, and the git directory. We can also see the conflicting commits by running git log -merge Aborting your merge during a merge conflict Here, everything after ++> main represents the branch you are merging in. Next, we can use git diff to see the difference between this branch and the one we are merging into: ++> main No changes added to commit (use "git add" and/or "git commit -a" )Īs we can see, only file.md is affected. " to mark resolution ) both modified: file.md (fix conflicts and run "git commit" ) (use "git merge -abort" to abort the merge ) Unmerged paths: Once you review all conflicts, you can then add your files and commit them as normal: “Compare Changes” - this will bring up an additional screen to compare changes side by side.“Accept Both Changes” - this will keep both, one under the other.“Accept Incoming Changes” - this will use the content from the branch you are merging in.“Accept Current Changes” - this will use your current branch’s content.In Visual Studio Code, this is represented in conflicting files via the GUI shown below. ![]() This provides a pretty easy way to fix your conflicts. If you’re using a modern code editor like Visual Studio Code, then merge conflicts will appear in the GUI where you can accept incoming changes or accept the current changes on your branch. How to resolve merge conflicts in git via GUI If we run into merge conflicts now, we need to resolve them. Now that our branch is stabilised, we can try to run git merge my-branch (where my-branch is your branch) to merge our branch back into main.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |