GitHub Basics - ashBabu/Utilities GitHub Wiki

Adding tags

  • git tag -a v1.0.0 -m "Working version of Ouster lidar and realsense-rtabmap slam
  • git tag # to view the tags
  • git push --tags # to push all the tags
  • `git push v1.0.01 # to push the specific tag

Add submodule

  • cd to the directory
  • git submodule add -b branch_name https:....url/of/the/repo

Not able to clone repos

solution

sudo nano ~/.ssh/config

And add the following

Host github.com
 Hostname ssh.github.com
 Port 443

To change the base of a branch here

lets say branch current has base branch named old_base . To change the base to a branch named new_base ,

  • git checkout current
  • git rebase --onto new_base old_base current

To pull all git branches locally

git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

git fetch --all # just for completeness

git pull --all


git fetch origin --prune # will delete all the branches locally that are deleted from remote

git merge --no-ff branch_name # will have all the commit histories

Stashing

  • git stash pop # to get back the stashed
  • git stash drop # to remove the stashed

Merge a branch with upstream

*. First commit the changes on the current branch
*. git fetch 'branch_name'
*. git merge upstream/branch_name
*. If needed push the changes

To pull all submodules here

git submodule update --init --recursive
OR
git submodule init
git submodule update

Revert a commit merged with remote

git rev-parse HEAD # To get the latest commit id

git revert {commit_id}'

git push origin/upstream branch/master

Pull a branch which is not merged with master

From here

  • Make note of the PR number.

  • Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

    $ git fetch upstream pull/37/head:pr37
    
  • Switch to that branch:

    $ git checkout pr37
    
  • Compile and test.

If the PR code changes and you want to update:

# Do this while in the pr37 branch
$ git pull upstream pull/37/head

Merging the PR

You can use the Github web interface, but there's a TOCTOU problem: If the pull-requester changes their master (or whatever they're PRing from) between the time you test and the time you merge, then you'll be merging code that you haven't reviewed/tested. So let's do it on the command line.

First, checkout the upstream master code:

You'll only do this the first time -- it creates the local upstream_master branch, tracks it to upstream_master, and switches to the branch:

$ git checkout -t -b upstream_master upstream/master

After the first time you'll just do:

$ git checkout upstream_master

Now merge the PR:

$ git merge pr37

NOTE: You should edit the merge commit message to reference the PR (using, say #37 in it).

Now push:

$ git push upstream HEAD:master

(You can't just git push because your local branch name is different than the remote.)

Done! Refresh the Github PR page and you'll see that the PR is now merged+closed.

Updating a fork and make it even with upstream

git fetch upstream

git checkout master

git rebase upstream/master or git merge upstream/master

git push origin master

Setup git

  • sudo apt-get install git
  • sudo apt-get install git gui # for graphical user interface (if needed)
  • git config --local (or --global) user.name "yourGithubName"
  • git config --local (or --global) user.email "yourGithubEmail"

To clone a repo

  • git clone https://github.com/ashbabu/MixedReality.git

To create a branch

  • git branch branch_name

To see all branches

  • git branch

To work in a branch (checkout)

  • git checkout branch_name

Work on the files in the branch. If file1 needs to be added to the remote

  • git add file1
  • git commit -m 'your short msg about the changes made to file1'

To push changes to remote repo

  • git push origin branch_name # to make it available in the branch of your repo

If a commit is made and later on if you want to undo the commit, git rm --cached name_of_file

Delete a file from git repository

git rm file1.txt

git commit -m "remove file1.txt"

To remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt"

Merging a branch

git merge origin master <branch_name> # merges the branch with master

git push origin <branch_name>

Delete a local and remote branch

git branch --delete <remote_name> <branch_name> ex: git push origin --delete test

Delete a local branch

git branch --delete <branch>

git branch -d <branch> # Shorter version

git branch -D <branch> # Force delete un-merged branches

How to do Forking and operate

Refer github1 github2

  1. Go to github.com and use fork button to fork the desired repository (orig_repo) to add to your local repositories (local_repo)

  2. git clone https:github.com/../local_repo.git Clone the local_repo to your PC.

  3. git remote add upstream https:github.com/.../orig_repo.git

  4. git fetch --all

  5. git checkout -b _name_of_ur_branch_

  6. Make changes to the code and commit it

  7. git push origin _name_of_ur_branch_

  8. Make pull request to upstream master (on github)

  9. Wait for it to be merged

  10. git checkout master

  11. git pull upstream/master

  12. Go to step 5

Merging a branch with the master

  1. git checkout master
  2. git pull origin master
  3. git merge test # test is the name of the branch
  4. git push origin master
⚠️ **GitHub.com Fallback** ⚠️