Git and Github Flashcards
(23 cards)
git config –global user.name “[name]”
This command sets the author name and email address respectively to be used with your commits.
git init [repository name]
This command is used to start a new repository.
git clone [url]
This command is used to obtain a repository from an existing URL.
git add [file]
This command adds a file to the staging area.
git add *
This command adds one or more to the staging area.
git commit -m “[ Type in the commit message]”
This command records or snapshots the file permanently in the version history.
git commit -a
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
git diff
This command shows the file differences which are not yet staged.
git diff –staged
This command shows the differences between the files in the staging area and the latest version present.
git diff [first branch] [second branch]
This command shows the differences between the two branches mentioned.
git reset [file]
This command unstages the file, but it preserves the file contents.
git status
This command lists all the files that have to be committed.
git log
This command is used to list the version history for the current branch.
git branch
This command lists all the local branches in the current repository.
git branch [branch name]
This command creates a new branch.
git branch -d [branch name]
This command deletes the feature branch.
git checkout [branch name]
This command is used to switch from one branch to another.
git merge [branch name]
This command merges the specified branch’s history into the current branch.
git push [variable name] master
This command sends the committed changes of master branch to your remote repository.
git pull [Repository Link]
This command fetches and merges changes on the remote server to your working directory.
Contribute to an existing repository
change into the repo
directory
git clone https://github.com/owner/repo.git
cd repo
git branch my-branch
git checkout my-branch
git add file1.md file2.md
git commit -m “my snapshot”
git push –set-upstream origin my-branch
Start a new repository and publish it to GitHub
create a new directory, and initialize it with git-specific functions
git init my-repo
cd my-repo
touch README.md
git add README.md
git commit -m “add README to initial commit”
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
git push –set-upstream origin main
How To Push Git Branch To Remote
$ git pull
$ git checkout my-feature
$ git merge origin/feature
$ git push origin my-feature:feature