Created
January 2, 2017 11:46
-
-
Save spham/00b2d5dcdae489f620419cf650b3620d to your computer and use it in GitHub Desktop.
Git bash cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add files to staging: | |
git add -A (visi faili) | |
vai: | |
git add filePath | |
Commit to local rep: | |
git commit -m 'METRO-82' | |
Push to branch/trunk (our branch name is develop) | |
git push origin develop | |
------------------------------ | |
GETTING AND CREATING PROJECTS | |
http://gitref.org/creating/ | |
initializes a directory as a Git repository (ls -a would give ".git" dir): | |
git init | |
copy a remote git repository: | |
git clone git://github.com/schacon/simplegit.git | |
git clone https://scm.sanoma.fi/git/is-secure-webapp.git | |
git clone https://scm.sanoma.fi/git/is-servicecore.git | |
> Initialized empty Git repository in /private/tmp/simplegit/.git/ | |
Short staging area status (what is there to commit): | |
git status -s | |
Add files and changes to commit staging area (index) | |
git add -A | |
Remove files and changes from commit staging area (index) | |
git reset HEAD <file> | |
git rm -r --cached . | |
Discard your changes for one of the files, replace with the commited version | |
git checkout <filename> | |
Do a hard pull (discard your local changes, take latest form the remote) | |
git fetch --all | |
git reset --hard origin/develop | |
//git fetch downloads the latest from remote without trying to merge or rebase anything. Then the git reset resets the develop branch to what you just fetched. | |
Short change summary status (from staging to local branch) | |
git diff --cached --stat | |
Short change summary status (from local to remote branch) | |
git diff origin/feature/rss --stat | |
diff between the tips of the two branches: | |
git diff branch_1..branch_2 --stat | |
Short change summary status (last commit difference) | |
git diff HEAD^1 --stat | |
Shift + Q to exit | |
Stash away (move to temp storage) your changes in the current branch: | |
git stash | |
Bring them back into current branch: | |
git stash apply | |
View what is in stash (Compare to stash): | |
git stash show | |
git stash show -p stash@{0} | |
Clear the stash: | |
git stash drop | |
Listing branches (both local and remote) | |
git branch -a -v | |
Listing branches (both local and remote) | |
> also shows the name of the upstream branch. | |
git branch -a -vv | |
Configure upstream branch: | |
git branch --set-upstream feature/registration origin/feature/registration | |
git branch --set-upstream feature/registration origin/develop | |
Switch to another local branch | |
git checkout feature/first | |
Checkout a remote branch creating a local branch: | |
git checkout -b feature/rss origin/feature/rss | |
> Branch feature/rss set up to track remote branch feature/rss from origin. | |
> Switched to a new branch 'feature/rss' | |
Fatch remote branch: | |
git fetch origin discover | |
Create a new branch: | |
git branch feature/new | |
Push a certain branch (not all local branches) | |
git push origin feature/new | |
Merge with a remote branch: | |
git merge origin/develop | |
Delete a branch: | |
git branch -D feature/new | |
git push origin --delete <branchName> | |
List git coniguration | |
git config -l | |
Tagging: | |
$ git tag | |
> list all tags | |
$ git tag -a 1.2 | |
> create a new tag | |
[Exit: ESC :wq] | |
Reverting branch to older revision (discarding some changes from branch): | |
git reset --hard <revision> (Easier done through Git History tool) | |
git push --force origin feature/modified | |
http://stackoverflow.com/questions/14386532/git-merged-two-branches-pushed-on-server-now-how-to-unmerge-them | |
----------------------------------------------------- | |
GIT Tracking feature: | |
List which remote branches are tracked (have pull/push targets) by local branches | |
git remote show origin | |
Local branches configured for 'git pull': | |
develop merges with remote develop | |
feature/registration merges with remote develop | |
feature/rss merges with remote feature/rss | |
Local refs configured for 'git push': | |
develop pushes to develop (up to date) | |
feature/registration pushes to feature/registration (up to date) | |
feature/rss pushes to feature/rss (up to date) | |
git checkout -b feature/rss -t origin/feature/rss | |
You can explicitly include the '-t' option when making the local branch to ensure it tracks the branch from which it originated from. | |
Remember a local branch can also track another local branch so doesn't have to be a remote branch. | |
When branches are created using the --track option, they will be set up to linked to the remote branch. For example, if you wanted to create a new branch from the master branch from the origin remote, using this would set it up so it would pull from the remote and branch automatically: | |
$ git branch --track feature1 origin/master | |
Branch feature1 set up to track remote branch refs/remotes/origin/master. | |
----------------------------- | |
VIM editor keys: | |
In vim, you save a file with :w Enter while in the normal mode (you get to the normal mode by pressing Esc). | |
You close your file with :q while in the normal mode. | |
You can combine both these actions and do Esc :wq Enter | |
-------------------------------- | |
GIT FLOW: | |
and check out git flow - it's a walk in the park after that | |
git flow feature start/publish/finish | |
git flow hotfix start/publish/finish | |
git flow release start/publish/finish | |
those macros do all the merges and such | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment