Difference between revisions of "Git Tips"

From TedYunWiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
Cheatsheet
 
Cheatsheet
git status -- state of commits of your local branch vs repository
+
 
 +
See state of commits of your local branch vs repository
 +
git status
  
 
You are working on a new feature - newfeat
 
You are working on a new feature - newfeat
 
1) create a new branch, newfeat
 
1) create a new branch, newfeat
  
> git checkout -b newfeat master
+
git checkout -b newfeat master
  
 
2) make changes, etc in your branch
 
2) make changes, etc in your branch
Line 13: Line 15:
 
3) push feature branch into repository
 
3) push feature branch into repository
  
> git push -u origin newfeat
+
git push -u origin newfeat
  
 
4) merge back into master
 
4) merge back into master
  
> git checkout master
+
git checkout master
> git merge --no-ff newfeat
+
git merge --no-ff newfeat
> git branch -d newfeat
+
git branch -d newfeat
> git push origin master
+
git push origin master
  
  
 
If master changes and you want to incorporate master changes into your branch:
 
If master changes and you want to incorporate master changes into your branch:
git rebase master
+
git rebase master
 
or
 
or
git merge master
+
git merge master
  
  
Line 41: Line 43:
 
To see the list of remote branches:
 
To see the list of remote branches:
 
  git branch -a
 
  git branch -a
 +
or
 
  git branch -r
 
  git branch -r
  
 
To update the list of remote branches:
 
To update the list of remote branches:
 
  git remote update origin --prune
 
  git remote update origin --prune

Revision as of 13:12, 13 August 2014

Git Tips

Cheatsheet

See state of commits of your local branch vs repository

git status

You are working on a new feature - newfeat 1) create a new branch, newfeat

git checkout -b newfeat master

2) make changes, etc in your branch

3) push feature branch into repository

git push -u origin newfeat

4) merge back into master

git checkout master
git merge --no-ff newfeat
git branch -d newfeat
git push origin master


If master changes and you want to incorporate master changes into your branch:

git rebase master

or

git merge master


Delete branch local: git branch -d old_branch remote: git push origin :old_branch

Undo last commit, 1) reset files to before you committed

    git reset --hard HEAD~1

2) just undo the "commit" action but leave everything else as is

    git reset --hard HEAD~1

To see the list of remote branches:

git branch -a

or

git branch -r

To update the list of remote branches:

git remote update origin --prune