Git documentation
git init
Initializes a new Git repository in the current directory.
git init Example: In an empty folder, this command will create a Git repository.
git clone
Clones a remote Git repository (e.g., from GitHub) into a local directory.
git clone <repository-url> Example: git clone https://github.com/user/project.git, this will download the project from the specified URL.
git status
Displays the status of the local repository, including modified, added, or staged files.
git status Example: After modifying a file, this command will show the state of the changes.
git add
Stages specific files to prepare them for the next commit.
git add <file-name> Example: git add file.txt, this adds the file file.txt for the next commit.
To add all modified files:
git add . git commit
Records the changes to the repository with a message describing them.
git commit -m "Descriptive message" Example:
git commit -m "Added login feature" git push
Sends the local commits to a remote repository.
git push <remote-name> <branch> Example:
git push origin main This will send the local commits to the main branch of the remote repository called origin.
git pull
Fetches and merges changes from a remote repository into the local branch.
git pull <remote-name> <branch> Example:
git pull origin main This fetches and merges changes from the main branch of the remote origin into your local branch.
git branch
Lists, creates, or deletes branches.
git branch git branch <branch-name> git branch -d <branch-name> git checkout
Switches between branches or restores files.
git checkout <branch-name> git checkout -b <new-branch> git merge
Merges changes from one branch into another.
git merge <branch-name> git log
Displays the commit history of the repository.
git log Example:
git log --oneline This displays the commit history in a compact format.
git remote
Manages remote repositories.
git remote -v git remote add <remote-name> <repository-url> Example:
git remote add origin https://github.com/user/project.git git fetch
Downloads commits from a remote repository without merging them.
git fetch <remote-name> Example:
git fetch origin git reset
Undoes changes by resetting the staging area or commit history.
git reset <file-name> git reset --hard <commit-hash> Example:
git reset --hard abc1234