git clone
Gets a Git repository from a remote source (makes a copy), so you could pull and push later.
Example with clones the repo with submodules:
git clone --recursive git://github.com/foo/bar.git
Example, alternatively cloning submodules later this way:
git clone git://github.com/foo/bar.git
cd bar
git submodule init
git submodule update
Example:git clone git@github.com:user/test.git
---
git identity - user name and email:
git config --global user.name "Alexander Tomov"
git config --global user.email tomov@example.com
---
git show url
git config --get remote.origin.url
git log origin/<branch>..HEAD
- shows local commits
git diff origin/<branch>..HEAD
- shows diff of local commits
git push
error: failed to push some refs to 'x'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
git pull --rebase
git status
Shows you the status of files in the index versus the working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing).
Example output:
# On branch xxxx
# Your branch is ahead of 'origin/xxxx' by 2 commits.
...
git push
git status
# On branch xxxx
# Changes not staged for commit:
Some important commands:
git branch -a
# list remote branches
git pull --recurse-submodules
# update all submodules (newer git clients)
git submodule foreach pull
# update all submodules (for older git clients)
git add
Adds files changes in your working directory to your index.
Example: git add .
git rm
Removes files from your index and your working directory so they will not be tracked.
TODO
Example: git rm filename
git commit
Takes all of the changes written in the index, creates a new commit object pointing to it and sets the branch to point to that new commit.
Examples: git commit -m ‘committing added changes’
git commit -a -m ‘committing all changes, equals to git add and git commit’
git commit --amend
It does a fast-fix for your last commit. In other words it joins your current commit with your last commit.
git merge
Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts.
Example: git merge newbranchversion
git reset
Resets your index and working directory to the state of your last commit.
Example: git reset --hard HEAD
git stash
Temporarily saves changes that you don’t want to commit immediately. You can apply the changes later.
Example:
git stash
Saved working directory and index state "WIP on master: 84f241e first commit"
HEAD is now at 84f241e first commit
(To restore them type "git stash apply")
git stash apply
Revert the changes made by "git stash"
git fetch
Fetches all the objects from the remote repository that are not present in the local one.
Example: git fetch origin
git log
Shows a listing of commits on a branch including the corresponding details.
Example: git log
commit 84f241e8a0d768fb37ff7ad40e294b61a99a0abe
Author: User <user@domain.com>
Date: Mon May 3 09:24:05 2010 +0300
first commit
git show
git show <commit_id>
Shows information about a git object.
Example: git show
commit 84e341e8a0d768fb37ff7ad40e294b61a99a0abe
Author: User <user@domain.com>
Date: Mon May 3 09:24:05 2010 +0300
first commit
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
Example: git show 84e341e8a0d768fb37ff7ad40e294b61a99a0abeq
Applies diff on the commit
git grep
Lets you search through your trees of content for words and phrases.
Example: git grep "www.siteground.com" -- *.php
git diff
Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory.
Example: git diff
Example: git diff path/to/file.txt
git config -l
Show git config, my identity information (name, email) and remote repository info (url)
git checkout
Discard changes
Example: git checkout file.txt
To reset one file in your working directory to its committed state:
Example: git reset --hard
To reset every file in your working directory to its committed state:
git mv old_name.txt new_name.txt
Rename a file
git update-index --assume-unchanged
To temporarily ignore changes in a certain file, run:
git update-index --assume-unchanged <file>
Then when you want to track changes again:
git update-index --no-assume-unchanged <file>
Reverting to previous commit
git checkout 0923d7fc32...
Where HEX id is the hash value from git status. Additional info and workflows could be found in that thread.
Switching to another branch
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/branch_to_switch
$ git checkout -b branch_to_switch remotes/origin/branch_to_switch
$
$ git checkout -b develop remotes/origin/develop
Showing only file names in commits
git log --name-only
-------------
Delete a Git tag
There are separate commands for deleting remote and local tags:
git push --delete origin tag_name
git branch -d the_local_branch
Show tags
git tag
Issue:
Branches 'develop' and 'origin/develop' have diverged.
And branch 'develop' may be fast-forwarded.
Solution:
git rebase origin/develop
------
Async-ed branch:
Symptom of async-ed develop branch:
# git remote show origin
...
Local branch configured for 'git pull':
master merges with remote master
git branch --set-upstream develop origin/develop
Symptom of async-ed develop branch:
# git remote show origin
...
Local branch configured for 'git pull':
master merges with remote master
(no develop here)
Local refs configured for 'git push':
...
git branch --set-upstream develop origin/develop
git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 1 commit.
# git remote show origin
Local branches configured for 'git pull':
develop merges with remote develop
master merges with remote master
# git checkout develop
Nice links:
Example workflow:
http://www.geekgumbo.com/2011/08/04/git-a-simple-workflow-commands-usage/
On undoing, fixing, or removing commits in git:
http://sethrobertson.github.io/GitFixUm/fixup.html
No comments:
Post a Comment