Carlos Gustavo Ruiz

Back to Notebook

Git

Set git user

Add and remove submodules

Get all submodules of a repo

Remove a submodule from a repo source

To remove a submodule you need to:

  • Delete the relevant line from the .gitmodules file.
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Commit and delete the now untracked submodule files.

Create remote branch

Configure git with push.default = current to make life easier:

-u will track remote branch of same name. No with this configuration you will auto-guess the remote reference to git push. From git.config documentation:

push.default

Defines the action git push should take if no refspec is explicitly given.

push.default = current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

Rename local branch

If you want to rename a branch while pointed to any branch, do:

If you want to rename the current branch, you can do:

source

Rename remote branch

If you want to rename (or move) a remote branch, type:

Remember to reset the upstream branch to the new name, switch to the branch and type:

Delete local branch

To delete a local branch type:

Delete remote branch

Type the following to delete a remote branch:

Check diff between local and remote branches

Steps:

  1. go to your repo and do git fetch
  2. type git diff <local_branch_name> <remote_branch_name>
  3. check your file changes
  4. make git merge

Some options to try in step 2 are:

  1. git diff --sumary FETCH_HEAD - gives an overview of the changes.
  2. git diff --stat FETCH_HEAD - gives more information than --summary.
  3. git diff FETCH_HEAD -- <some_dir/some_file> - show information only for a selected file.

source 1, source 2, source 3

Cloning a repo with HTTPS

cloning public repo

$ git clone https://github.com/atmantree/exercism.git

cloning using user and password (avoid this)

Create an orphan branch

Use of git stash

Use git stash to save the current state of the working directory of the repo, while we checkout another branch without commiting.

The command to get back the changes we made is git stash pop.

Update git subdirectories