Git Commands Flashcards
Add current working directory to the repository
git add .
Initialize a Git repository
git init
What command do you use to see what file was changed in your repository since the last commit
git status
Commit staged changes with a message
git commit -m ‘[message goes here]’
Track new file or stage file for commit
git add [file name]
Stage and commit all changes
git commit -a
What commas do you use to list the branches of a repository?
git branch
Switch branch
git checkout [branch name]
Merge branch to current working branch
git merge [branch name]
What command would you use to delete a branch label
git branch -d [branch name]
Stage and commit all changes with a message
git commit -am ‘[message goes here]’
Who would you upload changes from a repository named origin from your computer to a Github repository named master?
Git push origin master
Who would you download changes from a GitHub repository called upstream to a master repository in your computer?
Git pull upstream master
How do you view the commits history of the repository you are working on?
git log
What command is used to compare to commits in git
git diff [commit id] [commit id]
How would you check what are the differences between the working area and the staging area
git diff
How would you check what are the differences between the staging area and the latest commit
git diff –staged
After checking an older commit, how do you get back to the current commit with out knowing its ID?
git checkout master
Who do you create a new branch in a repository?
git branch [branch name]
Who would you create and move to a new branch using a single command?
git checkout -b [new branch]
How would you merge a branch called new_feature in to the master branch
git merge master new_feature
What command will list all remote repositories connected to the repository you are in?
git remote
Who do you connect a remote repository to your repository?
git remote add [remote name] [remote url]
What command will print the urls of your remote repository that you push to and pull from?
git remote -v