Terms in this set (28)
How to create a new repository?
create a new directory, open it and perform a git init
to create a new git repository.
How to checkout a repository?
Create a working copy of a local repository by running the command: git clone /path/to/repository
When using a remote server, your command will be:
git clone username@host:/path/to/repository
What is the git Workflow?
Your local repository consists of three "trees" maintained by git. the first one is your Working Directory which holds the actual files. The second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you've made.
How to add changes?
You can propose changes (add it to the Index) using:
git add <filename>
git add *
This is the first step in the basic git workflow.
How to commit your changes?
To actually commit these changes use:
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.
How to push your changes to master?
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute:
git push origin master
Change master to whatever branch you want to push your changes to.
How to create a new server to push to?
If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with:
git remote add origin <server>
Now you are able to push your changes to the selected remote server.
What is branching?
Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.
How to create a new branch and switch to it?
create a new branch named "feature_x" and switch to it using:
git checkout -b feature_x
How to switch back to the master branch?
switch back to master: git checkout master
How to delete a branch?
delete the branch again:
git branch -d feature_x
How to push a branch?
a branch is not available to others unless you push the branch to your remote repository: git push origin <branch>
How to update your local repo to the newest commit?
to update your local repository to the newest commit, execute:
in your working directory to fetch and merge remote changes.
How to merge another branch into your active branch?
to merge another branch into your active branch (e.g. master), use:
git merge <branch>
In both cases, git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with:
git add <filename>
before merging changes.
How to see the differences between two branches?
git diff <source_branch> <target_branch>
How to create a tag for releases?
it's recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named 1.0.0 by executing
git tag 1.0.0 1b2e1d63ff
the 1b2e1d63ff stands for the first 10 characters of the commit id you want to reference with your tag.
How to get the commit id and repo history?
How to see the commits from only one author?
git log --author=bob
How to see a compressed log where each commit is one line?
git log --pretty=oneline
How to see the ASCII art tree of the all the branches?
You want to see an ASCII art tree of all the branches, decorated with the names of tags and branches:
git log --graph --oneline --decorate --all
How to see only which files have changed?
git log --name-status
How to see more possible log parameters?
git log --help
How to replace local changes with the last content in the HEAD?
In case you did something wrong, which for sure never happens ;), you can replace local changes using the command
git checkout -- <filename>
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.
How to drop all local changes and commits, and get the latest history from the server?
If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this
git fetch origin
git reset --hard origin/master
How to see built-in git GUI?
How to see a useful colorful git output?
git config color.ui true
How to show log on just one line per commit?
git config format.pretty oneline
How to use interactive adding?
git add -i
YOU MIGHT ALSO LIKE...
Test Preparation TOEIC, SAT, TOEFL
OTHER SETS BY THIS CREATOR
Rider App 3 Native
THIS SET IS OFTEN IN FOLDERS WITH...