Fundamentals of Efficient Collaboration with Git — Commands
Understanding why version control is important is crucial. Version control plays a critical role in tracking changes, fixing errors, and collaborating in software development processes. In this writing, I will continue with the discussion of Git commands from my previous text. If you’re ready, let’s begin.
It Basic Concepts
Repository: It is the place where you store your projects. You can create local or remote repositories.
Commit: It is used to save code changes. Each commit represents a version.
Branch: By working in different code branches, you can create different versions of the same project.
Merge: The process of combining changes from different branches.
Pull Request: A mechanism used to review and approve code changes.
Clone: The process of copying a remote repository to your local machine.
Git Commands
git init:
Creates a new Git repository.git clone [repo-url]:
Copies a remote repository to your local machine.git status:
Shows the status of changes in the local repository.git add [file-name]:
Adds files to the staging area to track changes.git commit -m “[commit-message]”:
Records changes as a commit.git pull:
Fetches changes from a remote repository to the local repository.git pull [remote-repo][branch]:
Fetches and merges changes from a specific branch of a remote repository.git push:
Pushes local changes to a remote repository.git push [remote-repo][branch]:
Pushes a specific branch to a remote repository.git push [remote-repo]:[branch]:
Deletes a branch from a remote repository.git log:
Displays the commit history.git diff:
Shows differences between files.git branch:
Lists the current branches.git branch -D [branch-name]:
Deletes the specified branch in the local.git checkout [branch-name]:
Switches to a branch.git checkout -b [branch-name]:
Creates a new branch and switches to that branch.git checkout [commit-id] -- .:
The commit whose id is given implements existing structures.git merge [branch-name]:
Merges a branch into the current branch.git remote -v:
Shows the URLs of remote repositories.git stash:
Temporarily saves changes in the working directory.git stash list:
Lists temporarily stashed changes.git stash apply [stash-name]:
Applies changes from a specific stash.git stash drop [stash-name]:
Deletes a specific stash.git tag [tag-name]:
Adds a tag to a specific commit.git reset [commit]:
Reorganizes commit history.git rebase [branch-name]:
Rebases one branch onto another.git fetch:
Fetches changes from a remote repository without applying them.git fetch [remote-repo]:
Fetches changes from a specific remote repository.git remote add [name][url]:
Adds a remote repository to the local repository.git remote show [name]:
Provides detailed information about a remote repository.git remote remove [name]:
Removes a remote repository link from the local repository.git remote rename [old-name][new-name]:
Renames a remote repository link.git cherry-pick [commit]:
Applies a specific commit to the current branch.git blame [file-name]:
Shows which commit last modified each line in a file.git log --author=”[username]”:
Lists commits by a specific author.git log --grep=”[word]”:
Lists commits containing a specific word.git clean -n:
Lists untracked files (dry-run mode).git clean -f:
Deletes untracked files.git bisect start:
Searches for a bug in a previous commit.git archive --format=zip --output=[file-name.zip][branch]:
Exports the content of a branch to a ZIP file.git submodule init:
Initializes submodules.git submodule update:
Updates submodules.git help [command]:
Retrieves help for a specific Git command.
Result
In this and the previous Git article, we provided a general overview of the fundamental concepts, commands, and best practices of Git. Learning Git will help you make your software development processes more effective and organized. You can use this guide to start managing your projects better with Git.