Difference between revisions of "Git"

From John Freier
Jump to: navigation, search
(Rebase)
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
   git push --force origin feature_branch
 
   git push --force origin feature_branch
  
With force with lease, it will git will warm you if anyone else has committed any code, this helps to prevent overwriting someones code.
+
With force with lease, git will warn you if anyone else has committed any code, this helps to prevent overwriting someones code.
 
   git push --force-with-lease
 
   git push --force-with-lease
  
Line 35: Line 35:
 
A another way to view the logs.
 
A another way to view the logs.
 
   git log --oneline --decorate --graph --all
 
   git log --oneline --decorate --graph --all
 +
 +
 +
== Add all untracked changes. ==
 +
Here is a couple of commands to help with backing things up.
 +
This will add all untracked changes for a file type.
 +
  git ls-files --other | grep ".md" | xargs git add
 +
 +
This will add all tracked changes for a file type.
 +
  git ls-files | grep ".md" | xargs git add
 +
 +
 +
== Sign with GPG
 +
List your keys
 +
  gpg --list-secret-keys --keyid-format=long
 +
 +
 +
Update git to use a specific key.
 +
  git config --global user.signingkey 3AA5C34371567BD2
 +
 +
Sign all commits by default.
 +
  git config --global commit.gpgsign true

Latest revision as of 15:12, 1 March 2024

Rebase

When you are on a branch, you get

 git rebase master

You will get conflicts with the remote origin if you try and push. Here are some ways to solve this.


This will force the remote origin to stay up to date with your branch. But be aware, if there are more people working on the feature branch then just you, you may overwrite code.

 git push --force origin feature_branch

With force with lease, git will warn you if anyone else has committed any code, this helps to prevent overwriting someones code.

 git push --force-with-lease

Another good option after rebase with master is to just delete the branch on the remote origin, and then recreate it.

 git checkout myFeature
 git rebase master
 git push origin --delete myFeature
 git push origin myFeature

Squash feature branch

This squashes all the commits in to one.

 git merge --squash feature 

and then you need to commit the new squashed changes.

 get commit -m "squashed changes merged in."

Squash Commits

This squashes the last 3 commits.

 git reset --soft HEAD~3
 git commit -m 'new commit message'


View the logs

A another way to view the logs.

 git log --oneline --decorate --graph --all


Add all untracked changes.

Here is a couple of commands to help with backing things up. This will add all untracked changes for a file type.

 git ls-files --other | grep ".md" | xargs git add

This will add all tracked changes for a file type.

 git ls-files | grep ".md" | xargs git add


== Sign with GPG List your keys

 gpg --list-secret-keys --keyid-format=long


Update git to use a specific key.

 git config --global user.signingkey 3AA5C34371567BD2

Sign all commits by default.

 git config --global commit.gpgsign true