User Tools

Site Tools


manuals:git

3 steps git guide

*todo*

external resources

Working with branches

Before working with branches, you have to clone the main directory (git clone “directories_link”)
blue= terminal commands

  1. git status
  2. git checkout -b “new_branch” #Creates a new personal branch
  3. git branch / git branch -a #shows you on which branch you are working, -a shows you all branches
  4. git status
  5. Work on your files
  6. git add . #Adds your changed files
  7. git commit -m “message” #commit your changes, you can't checkout different branches without comiting changes
  8. git checkout master #switching to master branch
  9. git pull #get the latest master branch locally
  10. git merge new_branch -m “message” #merge new_branch changes with the master
  11. git status
  12. git push origin master #your branch changes should now be on github master branch repo


Useful GIT commands:

git rebase master #updates all your branches with the up to date master code

Deleting branches

  1. git delete -d branch_name #Delete local branch
  2. git push origin :branch_name #Delete remote branch

Overwrite your working branch:

  1. git branch fubar-pin #create a copy of your branch in the current position in case you want to retrieve it later
  2. git fetch –all #update your list of remote branches and sync new commits
  3. git reset –hard origin/branch #then, reset your branch to the point where origin/branch points to

troubleshooting with merging shells

In case of conflict after “merge”, go back to file where the conflict is. Decide what changes to keep. Save the file. Add the changed file git add .. Commit your changesgit commit -m “message”

deleting files from git

git filter-branch –force –index-filter 'git rm –cached –ignore-unmatch filename' –prune-empty –tag-name-filter cat – –all

troubleshooting vim

If you are in vim press ESC + shift + ; + wq or q

Headline

Comparing two branches

git diff --stat branch1..origin/staging (comparing remote branch)
git diff --stat branch1..branch2 (comparing local branch)

Git rebase workflow

At my dev shop we prefer to work with git rebase instead of git pull/merge to have a clearer history if the commits. In order to do this there are a few things necessary.

git pull --rebase

The idea behind is that instead of merging stuff one commit after the other will be applied on top of the head.

Getting the information where you are

git rebase -i

Picking which commits you want to use for your rebase, you can also pick single commits and apply them to your branch

git rebase -i staging

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 193 bytes) in /home_p2/d/o/domidesign.ch/htdocs/domicode.com/wiki/lib/plugins/authplain/auth.php on line 327