Bash-git-commands: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
(Created page with "Git commands that are useful for bash scripts. Retrieve the hash for the current commit inside whatever branch we are in This also works for submodules as long as you are wit...")
 
mNo edit summary
Line 1: Line 1:
Git commands that are useful for bash scripts.
Git commands that are useful for bash scripts.


Retrieve the hash for the current commit inside whatever branch we are in
* Retrieve the hash for the current commit inside whatever branch we are in
This also works for submodules as long as you are within the submodule directory in question
* This also works for submodules as long as you are within the submodule directory in question
<pre>
<pre>
git rev-parse HEAD
git rev-parse HEAD
<pre>
</pre>


Change the git remote from http(s) to git@ can be done this way:
* Change the git remote from http(s) to git@ can be done this way:
<pre>
<pre>
sed -i 's|https://URL/|git@URL:|g' ./.git/config
sed -i 's|https://URL/|git@URL:|g' ./.git/config
</pre>
</pre>
If you want to update the submodules
* If you want to update the submodules
<pre>
<pre>
sed -i 's|https://URL/|git@URL:|g' ./.gitmodules
sed -i 's|https://URL/|git@URL:|g' ./.gitmodules
sed -i 's|https://URL/|git@URL:|g' ./.git/modules/PATH/config
sed -i 's|https://URL/|git@URL:|g' ./.git/modules/PATH/config
</pre>
</pre>

Revision as of 11:02, 22 October 2021

Git commands that are useful for bash scripts.

  • Retrieve the hash for the current commit inside whatever branch we are in
  • This also works for submodules as long as you are within the submodule directory in question
git rev-parse HEAD
  • Change the git remote from http(s) to git@ can be done this way:
sed -i 's|https://URL/|git@URL:|g' ./.git/config
  • If you want to update the submodules
sed -i 's|https://URL/|git@URL:|g' ./.gitmodules
sed -i 's|https://URL/|git@URL:|g' ./.git/modules/PATH/config