A list of basic git commands
Some basic Git commands.
File classifications
Tracked
- Any file already in the repository or staged in the index.Ignored
- Any file that is declared invisible or ignored in the repository though present in the working directory.Untracked
- Any file that is neither tracked nor ignored.
Renaming a branch
This is from Renaming a branch on Github. Refer to this link for the authoritative instructions.
- Go to the main page of the repository.
- Click the Branches icon.
- Click the Edit icon to the right of the branch to be renamed.
- Type a new name for the branch in the Rename this branch field.
- Review the messages. They show the implications of renaming this branch.
- Click Rename branch. The branch is now renamed.
- Run the following set of commands on a local clone of the repository to update the name of the default branch:
$ git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME
$ git fetch origin
$ git branch -u origin/NEW-BRANCH-NAME NEW-BRANCH-NAME
$ git remote set-head origin -a
The branch is now renamed and a local clone has been updated.
Git command list
Command | Description |
---|---|
$ git | Git Help. |
$ git version | Provides version of git. |
$ git init | Create a repository. Create a directory, such as /example. cd to this directory and run git init to turn the directory into a repository. |
$ git add | Staging a file. For example, run git add index.html to add this file to the new repository. |
$ git status | Check the state of the repository. Shows which files need to be committed. |
$ git commit | Commits a file to the remote repository. |
$ git commit - m "A comment added to the commit" | Commits and adds comment. |
$ git commit --message | Same as git commit -m. |
$ git commit --all | Stages all known modified files and commits them. |
$ git log | View comments. |
$ git checkout branch_name | Switches to the branch provided in branch_name. |
$ git pull | Pulls from origin repository to make the local repo up-to-date. |
$ git checkout -b new_branch_name | Creates a new branch named new_branch_name. |
$ git rm filename | Removes file from both repository and working directory. |
$ git commit - "Remove a file called filename" | Same as git rm filename but adds a comment. |
$ git clone repository_directory new_repository_directory | Makes a copy (a clone) of a repository |
$ git mv filename newfilename | Moves a file to a new filename (same as renaming. |
$ git commit -m "renamed filename to newfilename" | Renames a file. |
$ git remote prune origin | Remove tracking references to the old branch name. |