Git is a popular version control system used by both administrators and developers to manage code and collaborate on software projects. Here are some common commands used by both roles:
Common Git Commands for Developers:
git clone
: Copies a repository from a remote server to your local machine. Example:git clone <repository_url>
git add
: Adds changes in your working directory to the staging area, preparing them for a commit. Example:git add <file>
orgit add .
(to add all changes)git commit
: Creates a new commit with the changes from the staging area. Example:git commit -m "Commit message"
git push
: Uploads local commits to a remote repository. Example:git push origin <branch_name>
git pull
: Fetches and merges changes from a remote repository to your local branch. Example:git pull origin <branch_name>
git status
: Shows the current status of your working directory and staging area.git log
: Displays the commit history for the current branch.git branch
: Lists all branches in the repository. Example:git branch
orgit branch -a
(to show all branches, including remote ones)git checkout
: Switches to a different branch or commit. Example:git checkout <branch_name>
orgit checkout <commit_hash>
git merge
: Integrates changes from one branch into another. Example:git merge <branch_name>
git stash
: Temporarily stores changes that are not ready to be committed. Example:git stash
orgit stash save "message"
Common Commands for Administrators:
git init
: Initializes a new Git repository in the current directory.git remote
: Manages connections to remote repositories. Example:git remote add <name> <repository_url>
git fetch
: Downloads objects and refs from another repository. Example:git fetch origin
git push
: Uploads local commits to a remote repository. Example:git push origin <branch_name>
git pull
: Fetches and merges changes from a remote repository to the current branch. Example:git pull origin <branch_name>
git clone
: Copies a repository from a remote server to your local machine. Example:git clone <repository_url>
git log
: Displays the commit history for the current branch.git branch
: Lists all branches in the repository. Example:git branch
orgit branch -a
(to show all branches, including remote ones)git checkout
: Switches to a different branch or commit. Example:git checkout <branch_name>
orgit checkout <commit_hash>
git merge
: Integrates changes from one branch into another. Example:git merge <branch_name>
git tag
: Creates, lists, or deletes tags to mark specific points in history. Example:git tag <tag_name>
orgit tag -a <tag_name> -m "Tag message"
These commands provide a starting point for using Git effectively as both an administrator and a developer. There are many other advanced commands and workflows that you can explore as you become more comfortable with Git.