Git Commands Flashcards
git init
Initializes the folder as the project root and as a git repository
git add index.html
git add .
First adds index.html to the staging area
Second adds all files to the staging area
git add name*
adds files that start with ‘name’ to the staging area
git status
shows the repository status:
staged, unstaged, and untracked files
git commit
opens a text editor in the terminal to write a commit message
git commit -m “commit message”
writes the commit message without opening up an editor, everything in quotes is the message
git log
shows the commit history
git log -p
shows commit history including all files and their changes
git diff
git diff –staged
git diff shows all unstaged changes
adding –staged to see staged changes
git rm filename
will remove the file from the working tree and expect a commit message as to why
git mv oldName newName
renames files in git, expects a commit message
How do you ignore files in git?
create a .gitignore file and commit it
git reset HEAD filename
git reset HEAD -p
reverts staged changes in git
-p options flag to specify the desired changes to reset
git commit –amend
modifies the most recent commit
avoid if possible
git revert HEAD
reverts the latest commit
git revert commit_id
revert an older commit, opens up an editor for commit message
git branch name
creates a new branch with the name provided
git checkout branch
changes over to the declared branch
git branch
lists all branches for the repository
git checkout -b name
will create a branch and switch to it immediately
git branch -d branch_name
will delete the declared branch
git merge branch_name
merges the branch you are in with the branch declared
git log –graph –oneline
shows the commit log as a graph, can use –all to show all branches
git remove -v
shows all remote repositories at your local repository
git add remote https://repo…
adds a remote repository to your local repository
git push
pushes all changes to the remote repository
git pull
retrieves the latest changes to the remote repository and performs a merge
git fetch
downloads the changes from a remote repo, but will not perform a merge with your local repository
git push -u origin branchName
pushes to a new ‘upstream’ branch
-u ‘upstream’
git push -f
forces a push request, usually fine for pull request branches but should not be performed on public repos.
git branch -M main
renames primary branch to main
git clone https://remote.git
will clone a remote repository to the current directory