0% found this document useful (0 votes)
64 views

Git-Commands: Other References

The document provides an overview of common Git commands, describing their purpose and functionality. It lists commands for initializing and cloning repositories, adding and committing changes, branching and merging, sharing code through remote repositories, and more advanced commands for inspecting changes and cleaning up files.

Uploaded by

Saurabh Dixit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Git-Commands: Other References

The document provides an overview of common Git commands, describing their purpose and functionality. It lists commands for initializing and cloning repositories, adding and committing changes, branching and merging, sharing code through remote repositories, and more advanced commands for inspecting changes and cleaning up files.

Uploaded by

Saurabh Dixit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Git-Commands

Purpose Command Description Other References

Getting git init Initialize a local Git repository

& git clone ssh://git@git Create a local copy of a remote repository GitHub - dahlbyk/posh-git: A
hub.com/[username]/ PowerShell environment for Git
Creatin Creating a personal access
[repository-name].git
g token - GitHub Docs
https://askubuntu.com
Projects /questions/206449/git-config-
global-file-remove-settings
Basic git status Check status https://docs.microsoft.com/en-
Snaps us/azure/devops/repos/git
git add [file-name.txt] Add a file to the staging area
/ignore-files?view=azure-
hotting devops&tabs=visual-studio
git add -A Add all new and changed files to the staging area
https://git-scm.com/docs
git commit -m Commit changes /gitignore
"[commit message]" How To Rename a Local and
Remote Git Branch | Linuxize
git rm -r [file-name.txt] Remove a file (or folder)

Branch git branch List branches (the asterisk denotes the current branch)

ing & git branch -a List all branches (local and remote)
Merging
git branch [branch Create a new branch
name]

git branch -d [branch Delete a branch


name]

git push origin -- Delete a remote branch


delete [branch name]

git checkout -b Create a new branch and switch to it


[branch name]

git checkout -b Clone a remote branch and switch to it


[branch name] origin/
[branch name]

git branch -m [old Rename a local branch


branch name] [new
branch name]

git checkout [branch Switch to a branch


name]

git checkout - Switch to the branch last checked out

git checkout -- [file- Discard changes to a file


name.txt]

git merge [branch Merge a branch into the active branch


name]

git merge [source Merge a branch into a target branch


branch] [target
branch]

git stash Stash changes in a dirty working directory

git stash clear Remove all stashed entries

Sharin git push origin Push a branch to your remote repository


[branch name]
g&
Updati git push -u origin Push changes to remote repository (and remember the branch)
[branch name]
ng
Projects git push Push changes to remote repository (remembered branch)

git push origin -- Delete a remote branch


delete [branch name]

git pull Update local repository to the newest commit


git pull origin [branch Pull changes from remote repository
name]

git remote add origin Add a remote repository


ssh://[email protected]/
[username]/
[repository-name].git

git remote set-url Set a repository's origin branch to SSH


origin ssh://git@githu
b.com/[username]/
[repository-name].git

Inspect git log View changes

ion & git log --summary View changes (detailed)


Compa
git log --oneline View changes (briefly)
rison
git diff [source Preview changes before merging
branch] [target
branch]

Advan git clean -n To see which files will be deleted

ce git clean -f It will delete the files for real


Snaps
git clean -f -d or git To remove directories
hotting clean -fd

git clean -f -X or git To remove ignored files


clean -fX

git clean -f -x or git To remove ignored and non-ignored files


clean -fx

Git Ignore git rm -r /path/to/dir To ignore something already added to the repo, you have to do
git rm -r /path/to/dir and commit that before you add
the dir to your .gitignore file. Otherwise the only thing git will
ignore is your ignore directive.

You might also like