A few examples to illustrate use of git
on the command-line.
PLEASE READ CAREFULLY the CONTRIBUTING.md
file in this directory. You must follow the specified flow to contribute to this repository.
If you have a suggestion to improve this document please either submit a pull-request, open an issue or email [email protected].
- Place all your working copies in easy-to-find directories. A suggested
nominclature is:
$HOME/GitHubRepos/<GitHub_Account>/<Repository/><Branch>
- Use unique and easily recognizable names for your branches. Suggested
nominclatures are:
<org>_<userid>_yyyymmdd (e.g ohw_mike_20191120)
or:
<org>_<userid>_issue_<num> (e.g ohw_mike_issue_239)
Examples:
- /home/mike/GitHubRepos/openhwgroup/core-v-verif/master
- /data/mike/GitHubRepos/openhwgroup/core-v-verif/ohw_mike_20191204
- /wrk/greg/GitHubRepos/openhwgroup/cv32e40p/master
- /home/mike/GitHubRepos/MikeOpenHWGroup/core-v-docs/ohw_mike_issue_123
"$" is the prompt. "#" is a comment line. ">" is git output to stdout.
Note that this is not a typical use-case (work on a branch instead).
Place all your working copies in easy-to-find directory:
e.g. $HOME/GitHubRepos/<GitHub_Account>/<Repository>/<branch>
$ cd $HOME/GitHubRepos/openhwgroup/cv32e40p
$ git clone --recursive https://github.com/openhwgroup/cv32e40p
$ gvim Makefile #...edit file(s)...
$ git commit -m 'Added support for dsim' Makefile
# First time users might be asked to update their info...
$ git config --global --edit
$ git commit --amend --reset-author
$ cd $HOME/GitHubRepos/openhwgroup/cv32e40p
$ git clone --recursive https://github.com/openhwgroup/cv32e40p ohw_mike_20191121
$ git branch ohw_mike_20191121
$ git checkout ohw_mike_20191121
...or...
$ git checkout -b ohw_mike_20191121
# ...edit file(s)...
# push files back to the branch
$ git status # check to see what's different
$ git remote -v # check to ensure remote is the branch you want
$ git commit -m 'Useful commit message'
$ git push --set-upstream origin ohw_mike_20191122
$ cd $HOME/GitHubRepos/openhwgroup/cv32e40p
$ git clone --recursive -b ohw_mike_20191122 https://github.com/openhwgroup/cv32e40p ohw_mike_20191122
$ git log --pretty=format:'%h' -n 1
$ cd $HOME/GitHubRepos/<GitHub_Account>/
$ git checkout master
$ git pull
$ git checkout
$ git merge master
$ git push --set-upstream origin
The following assumes you have previously created a fork of
https://github.com/openhwgroup/core-v-docs
to
https://github.com/MikeOpenHWGroup/core-v-docs
$ cd GitHubRepos/MikeOpenHWGroup/core-v-docs
$ git clone https://github.com/MikeOpenHWGroup/core-v-docs.git master
$ cd master
$ git remote -v
> origin https://github.com/MikeOpenHWGroup/core-v-docs.git (fetch)
> origin https://github.com/MikeOpenHWGroup/core-v-docs.git (push)
$ git remote add upstream https://github.com/openhwgroup/core-v-docs.git
$ git remote -v
> origin https://github.com/MikeOpenHWGroup/core-v-docs.git (fetch)
> origin https://github.com/MikeOpenHWGroup/core-v-docs.git (push)
> upstream https://github.com/openhwgroup/core-v-docs.git (fetch)
> upstream https://github.com/openhwgroup/core-v-docs.git (push)
$ git fetch upstream
$ git checkout master
$ git merge upstream/master
$ git push --set-upstream origin master
- Make sure you've pulled the new upstream branch into your local repo:
- First, ensure your working tree is clean (commit/stash/revert any changes), then:
$ git fetch upstream to retrieve the new upstream branch
- Create and switch to a local version of the new upstream branch (newbranch):
$ git checkout -b newbranch upstream/newbranch
- When you're ready to push the new branch to origin:
$ git push -u origin newbranch
The -u switch sets up tracking to the specified remote (in this example, origin).
# git remote set-url origin [email protected]:username/your-repository.git
$ git clone [email protected]:openhwgroup/core-v-verif.git master
$ git remote add metrics [email protected]:cv32e40p_verif/cv32e40p_verif.git
$ git remote -v
> metrics [email protected]:cv32e40p_verif/cv32e40p_verif.git (fetch)
> metrics [email protected]:cv32e40p_verif/cv32e40p_verif.git (push)
> origin https://github.com/openhwgroup/core-v-verif (fetch)
> origin https://github.com/openhwgroup/core-v-verif (push)
# https://stackoverflow.com/questions/3042437/how-to-change-the-commit-author-for-one-specific-commit
# https://docs.github.com/en/github/getting-started-with-github/about-git-rebase#an-example-of-using-git-rebase
$ cd <working_dir>
$ git rebase --interactive HEAD~7
# This pops an editor session of the last seven commits
# In this example, change two commits from "pick" to "edit"
# Quit the editors and then do the following at the command-line...
$ git commit --amend --author="Mike Thompson [email protected]" --no-edit
$ git rebase --continue
$ git commit --amend --author="Jean-Roch Coulon [email protected]" --no-edit
$ git rebase --continue
$ git remote -v
$ git push -f