luisfmelo
3/9/2017 - 1:29 PM

Git experiments

  • Merge branches
  • Keep fork branch up to date
  • Generate and add ssh key to github
  • Change commit text
  • Add File to previous commit
  • Fix git permissions
# Create the branch on your local machine and switch in this branch
git checkout -b new_branch

# Push the branch on github
git push origin new_branch

# When you want to commit something in your branch, be sure to be in your branch

# You can see all branches created by using
git branch


################# Actual Merge
git checkout master
git pull origin master
git merge new_branch
git push origin master
# 1. Clone your fork:
git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

# 2. Add remote from original repository in your forked repository:
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

# 3. Updating your fork from original repo to keep up with their changes:
git pull upstream master
ssh-keygen -t rsa -b 4096 -C "example@email.com"
ssh-add ~/.ssh/id_rsa
sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_rsa.pub

# Ctrl + V em: Settings > SSH and GPG keys > New SSH key

# Now... test connection:
ssh -T git@github.com
# input: yes
# To make changes to your most recent commit use:
git commit --amend

#For example, you might want to edit the name of the commit:
git commit -m 'my first comit'
git commit --amend

# Editor opens
# > 'my first commit'


#This is also useful for when you forget to add a file. The amend option will use your current staging area to overwrite the previous commit:

echo "Enki" > README.md
git add README.md
git commit -m 'my first commit'
echo "Rocks" >> README.md
git add README.md
git commit --amend

# Editor
# > My first commit


# The result is a single commit with message My first commit and changes to README.md:
# > Enki
# > Rocks

# The commit with the message my frst comit is overridden by a new one.
echo "Enki" > README.md
git add README.md
git commit -m 'my first commit'
echo "Rocks" >> README.md
git add README.md
git commit --amend

# Editor
# > My first commit


# The result is a single commit with message My first commit and changes to README.md:
# > Enki
# > Rocks

# The commit with the message my frst comit is overridden by a new one.
# Problem:
# error: insufficient permission for adding an object to repository database .git/objects
# fatal: failed to write object
# fatal: unpack-objects failed
 
cd /path/to/repo.git
sudo chgrp -R ubuntu .  # Here ubuntu is the group name of the user you want to give access
sudo chmod -R g+rwX .
sudo find . -type d -exec chmod g+s '{}' +