-
Notifications
You must be signed in to change notification settings - Fork 0
Useful GIT Commands
Hernan G. Arango edited this page Feb 19, 2026
·
1 revision
| Command | Description |
|---|---|
| git add <FileName> | Add a file to the repository staging area |
| git branch | List all local branches (the asterisk denotes the current branch) |
| git branch -a | List all local and remote branches |
| git branch -d <BranchName> | Delete a local branch |
| git branch -D <BranchName> | Delete a local branch forcefully |
| git branch -m <OldName> <NewName> | Rename a local branch |
| git checkout -b <BranchName> | Create a new local branch and switch to it |
| git checkout <BranchName> | Switch to an existing local or remote branch |
| git clone <RepositoryURL> | Clone a public repository |
| git commit -am "<Message>" | Commit changes to all files |
| git commit -am "<Message>" -m "<MessageURL>" | Commit changes to all files with two message lines |
| git commit --amend -m "<NewMessage>" | Amend previous commit message |
| git config -l | List all the variables set in the config file, along with their values |
| git diff | Show all changes between HEAD and working branch |
| git diff <FileName> | Show changes for a specific file between HEAD and working branch |
| git difftool -d <BranchName1> <BranchName2> | Compare the difference between two branches with KDIFF3
|
| git fetch | Retrieve new work done by other people |
| git fetch origin --prune | Remove tracking of any deleted remote branch in your local repository |
| git log | View repository changes |
| git log --oneline | Show the list of commits in one-line format |
| git log --summary | View repository detailed changes |
| git merge --no-ff --no-commit <BranchName> | Merge a branch into the active branch |
| git pull | Update local repository or branch to the newest origin commit |
| git pull -p | Remove/Prune any local tracking branch that no longer exists on the remote |
| git push origin --delete <BranchName> | Delete a remote branch |
| git push -u origin <BranchName> | Push changes to the remote repository (and remember the branch) |
| git reset --hard HEAD~1 | Undo last commit |
| git revert <CommitID> | Revert commit changes |
| git rm --cached filename | Removes file from repository |
| git stash | Store current branch uncommitted temporarily changes to work on another branch |
| git stash apply stash@{1} | Like pop, but do not remove the state @{1} from the stash list |
| git stash list | List stashed modifications |
| git stash pop stash@{1} | Remove stashed state @{1} from the stash list and apply it on top of the current branch |
| git stash show | Inspect stashed modifications |
| git status | Check/display changes to the repository or particular branch |
| git tag | List all tags |
Complicated Commands:
- If a branch is renamed in a repository on GitHub, the local clone on a computer needs to be updated:
git branch -m OldName NewName
git fetch origin
git branch -u origin/NewName NewName
git remote set-head origin -a- How to merge changes in the feature/name1 branch into the feature/name2 branch:
git checkout feature/name1
git pull
git checkout feature/name2
git pull
git merge --no-ff --no-commit feature/name1
git commit -am "Merging feature/name1 into feature/name2" -m "MessageURL"
git difftool -d feature/name1 feature/name2
git push -u origin feature/name2- Configuring a repository with two origins. For example, the following steps are executed to create a public ROMS-JEDI from its private repository:
git clone https://github.com/JCSDA-internal/roms-jedi myroms-jedi
git remote remove origin
git remote add origin https://github.com/myroms/roms-jedi
git config -f .lfsconfig lfs.https://github.com/myroms/roms-jedi.git/info/lfs.access=basic
git config -l
git remote add jcsda-origin https://github.com/JCSDA-internal/roms-jedi
git pull origin develop
git branch --set-upstream-to=origin/develop develop- Then, when updating, use the following steps to merge the
github/JCSDA-privatedevelop intogithub/myroms/roms-jedidevelop branch:
git config pull.rebase true (must be done once per local repository)
git pull jcsda-origin develop
git pull
git push (Bypasses rule violations for refs/heads/develop)
git pull jcsda-origin -p (prunes deleted jcsda-origin branches)East Coast Community Ocean Forecast System (ECCOFS)