Difference between revisions of "Linux command: git"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) |
Rafahsolis (talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | == Install== | ||
| + | sudo add-apt-repository ppa:git-core/ppa -y | ||
| + | sudo apt-get update | ||
| + | sudo apt-get install git | ||
| + | git --version | ||
== Clone == | == Clone == | ||
git clone <repository_path> | git clone <repository_path> | ||
Revision as of 00:03, 2 April 2016
Install
sudo add-apt-repository ppa:git-core/ppa -y sudo apt-get update sudo apt-get install git git --version
Clone
git clone <repository_path>
add/commit/push
git add . git add -A git commit -m "Message of commit" git push origin master
Branching
git checkout -b <branch_name> git merge
git Successful Feature Branching Workflow
Onece you have cloned the master repository:
- Create a branch for each feature
- Merge branches with --no-ff
git checkout -b <branch_name>
Write your new code Switch to the master branch to merge
git merge --no-ff <brach_to_merge_name>
Set the current branch to specific commit:
git reset --hard f414f31
Undo last changes
git checkout -- .
add remote
git remote add <repository_name> <repository_path>
list remote
git remote -v
Modify remote url
git remote set-url origin <new_url/new_repository.git
remove remote
git rm <repository_name>
pull/push
git push <repository_name> git pull <repository_name>
To push all branches:
git push --all origin
Tags
To fetch tags:
git fetch --tags
To push tags:
git push origin --tags
Full copy of remote repository:
#!/bin/bash
for branch in `git branch -r | grep -v HEAD | grep -v master`; do
echo ${branch##*/} $branch
done
git fetch --all
git pull -v
Add .gitignore
Add the file to the git folder To stop following and delete the files that were allready being tracked:
git rm -r --cached . git add . git commit -m ".gitignore now working"
- To undo git rm --cached filename use: git add filename
git config
git config --global push.default [matching | simple] git config --global user.name "Nombre Apellido" git config --global user.email "user@domain.com"
assume-unchanged
This will make git to stop tracking changes on <file>
git update-index --assume-unchanged <file>
To include again this file run:
git update-index --no-assume-unchanged <file>
To view which files are not being tracked:
git ls-files -v|grep '^h'
Set upstream branch
git branch --set-upstream-to=origin/master
Change last commit
git commit --amend
Change older commit messages
git rebase -i HEAD~n
Replace pick with reword before each commit message you want to change.
Save and close the commit list file.
In each resulting commit file, type the new commit message, save the file, and close it.
git push --force
Cheat Sheet
http://wiki.herrerosolis.com/images/4/46/Git-cheat-sheet.pdf