git

Useful Commands

You have a folder full of files and you know want to add to a new Git repository, follow these steps:

https://blog.mruckman.com/2026/01/add-files-to-a-new-git-repository/

How do I remove files saying "old mode 100755 new mode 100644" from unstaged changes in Git?

Refer: https://stackoverflow.com/questions/1257592/how-do-i-remove-files-saying-old-mode-100755-new-mode-100644-from-unstaged-cha

git config core.filemode false

If you keep these setting permanently, git won't remember your file attributes properly. This happened because I used rsync to copy files.

You can change the file modes back with this command:

chmod 644 <filename>

Store credentials globally Ubuntu

git config --global credential.helper store

$ git status

Installation

$ apt-get -y install git
$ git config --global http.sslVerify false

Hard Reset a BAD Merge
$ git checkout develop
$ git fetch --all
$ git reset --hard origin/develop

Create a Local Repository
$ git init
$ git add .
$ git commit -m "baseline"

Rollback a change
$ git checkout my-changed-file.txt
Or rollback all changes
$ git checkout .

Checking Out a Branch
$ git clone --branch destornillador --progress -v "https://github.com/hollandamerica/webintegration" "C:\Temp\webintegration"

Delete a Local Branch
$ git branch -d the_local_branch

Currently Being Used for GUI / Dataprism
$ git clone --branch development --progress -v "https://mruckman@github.com/hollandamerica/webintegration" "/home/jboss1/workspace/development-gui"

Update Command
$ git remote update

Adding Files
$ git add *
$ git add file-name.extension

Committing Files
$ git commit -m "Adding files for this reason"

Pushing Changes Back Into Repository
$ git push origin master

Revert Several Merges
Note: Create a feature branch to rollback changes, then in LIFO order

$ git revert --no-commit SHA-1(C)
$ git revert --no-commit SHA-1(B)
$ git revert --no-commit SHA-1(A)
$ git commit -m "rolling back changes"

How to Update Your Local Copy with Your Changes
$ git stash
$ git rebase
$ git apply stash

Switching Repository
$ git checkout -b <branch-to-use>
$ git pull origin <branch-to-use>

Example for GUI:
$ git checkout -b development
$ git pull origin development

Information About Repository with Details
$git remote show origin

Quick Look at Local Repo for Its Branch Name
$ git branch -lv

Using git with Meld
Refer: http://vpalos.com/1370/visualizing-git-diffs-in-meld/

Configure git for meld:
$ git config --global diff.tool meld
$ git config --global difftool.prompt false

Now compare like this:
$ git difftool

Using meld for Merge Conflicts
$ git config --global merge.tool meld
$ git config --global mergetool.prompt false

Now use it like this:
$ git mergetool

Creating  Patch
$ git format-patch -<n> <sha>
Where <n> is the number of patches from <sha>

$ git format-patch -1 a70be98199d1f036f5d037769338b14297a5abcc

Apply Patch
Note: This command does not apply the patch, but only shows you the stats about what it’ll do. After peeking into the patch file with your favorite editor, you can see what the actual changes are.

$ git apply --stat my-fix.patch

Next, you’re interested in how troublesome the patch is going to be. Git allows you to test the patch before you actually apply it.
$ git apply --check my-fix.patch

If you don’t get any errors, the patch can be applied cleanly. Otherwise you may see what trouble you’ll run into. To apply the patch, I’ll use git am instead of git apply. The reason for this is that git am allows you to sign off an applied patch. This may be useful for later reference.
$ git apply my-fix.patch
$ git am --signoff my-fix.patch

Leave a Reply