git clone https://github.com/<user-name>/<repo-name>.git
git branch -va
git status
git commit -m "commit message"
git commit -am "commit message"
git push
git remote -v
git fetch upstream
git checkout <branch-name>
git merge upstream/<branch-name>
git push
git logg
git show summary
git restore .
git restore <filename>
git fetch origin --prune
git config --global --add --bool push.autoSetupRemote true
Reset local master branch - when local master is ahead of remote/origin by X commits from local merges
git reset --hard origin/master
git log --all --graph
- Check status
git status
- Stash changes - this will stash tracked and untracked changed files
git stash --include-untracked
- Verify stash happened and that your working status is clean
git status
- Fetch and merge changes from desired branch
git pull <remote-name> <remote-branch-name>
- Assuming fast-forward occurs (no manual merging needed), then pop changes off stash
git stash pop
- Ensure local branch is on master, because we want to merge into local master, from upstream master
git checkout master
- fetch changes from upstream to local
git fetch upstream
- merge changes from fetched upstream master branch to to local master branch. this will merge into whatever the current selected branch is, from the name provided as a parameter
git merge upstream/master
- push changes to forked repo in Github (developer's repo)
git push origin master
- We want to do this to keep a clean Git history, or to be able to say "I'm working on my feature from the latest version of master everyone else is using"
- This needs to happen with the feature branch checked out
- follow steps above to update local master, then do the following:
git checkout develop
git rebase master
- WARNING: NEVER, EVER, EVER rebase on a public branch
Do this while whatever feature branch your are working on is checked out
-
git pull upstream master --rebase
-
git push origin feature-branch-name --force
(--force is required, otherwise it won't be allowed) -
If there are merge conflicts
git mergetool
.. or use your merge tool of choice (Visual Studio, VS Code)git commit -am "Fix merge conflicts"
commit the final versions of the merged file(s)git rebase --continue
tell the rebase to continuegit push origin feature-branch-name
push to your origin,--force
should not be required here
- when a co-worker submits a PR and you want to pull to your local and verify before approving
git remote add <remote-name> https://github.com/<username>/<repo-name>.git
git fetch <remote-name> <branch-name-source>:<branch-name-target>
git checkout <branch-name>
- note 1: add the remote to the users repo, NOT the repo with branch
- note 2: the branch name must be different (unsure why)
- when a co-worker submits a PR and you want to pull and test, but from the PR branch in Github, instead of the co-workers direct repo
- Fetch the reference to the pull request based on its ID number, creating a new branch in the process.
git fetch <remote-name> pull/<PR-ID#>/head:<branch-name>
- ex:
git fetch upstream pull/59/head:feature-KINT-198
- ex:
- Github - Checking out Pull Requests locally
- delete master branch:
git branch -D master
- fetch changes from upstream:
git fetch upstream
- make sure you are on master branch:
git checkout master
- perform a hard reset to upstream/master:
git reset --hard upstream/master
- force push to your forked repository:
git push origin master --force
user is on develop branch
- pull in changes from upstream:
git fetch upstream
- stash unstaged changes on develop branch:
git stash
- checkout master branch:
git checkout master
- merge master:
git merge upstream/master
- checkout develop branch:
git checkout develop
- unstash changes:
git stash pop
git config --global alias.logg "log --graph --decorate --pretty=oneline --abbrev-commit --all"
git config --global alias.branch-name "rev-parse --abbrev-ref HEAD"
git config --global alias.pub "git push -u origin $(git branch-name)"
This allows you to rungit pub
to push your new local branch to the repo
git config --get-regexp alias
find . -name "filename.txt"
- type
gitk
in source directory to open a GUI