newdevs:git:commands
This is an old revision of the document!
Table of Contents
New Developers Working Group
Git for Windows
Useful Commands
Git Commands
git add myfile.txt
–> stage a specific filegit add -A
–> stage all modified files in the current directory and subdirectoriesgit add .
–> (Note the period) stage all modified files in the current directory but not subdirectoriesgit branch
–> list existing local branchesgit branch mynewbranch
–> create a new branchgit branch -m oldbranchname newbranchname
–> change name of branchgit branch -D branchname
–> delete a local branch (cannot delete a branch you currently have checked out, so switch to different branch first)git checkout mybranch
–> check out an existing branchgit checkout -b mynewbranch
–> create a new branch and check it out at the same timegit checkout master
–> switch to master branchgit checkout – docname.tt2
–> resets a file you've changed back to its original state (like an undo / revert changes command)git cherry-pick <hash>
–> apply a specific commit to your local branchgit cherry-pick -s <hash>
–> apply a specific commit to your local branch with your signoffgit cherry-pick -s <first hash>^..<last hash>
–> apply a range of commits with your signoff to your local branchgit clone git://git.evergreen-ils.org/Evergreen.git
–> clones a remote repositorygit commit
–> invoke the default text editor to add a commit messagegit commit -m "my commit message"
–> add brief commit message instead of opening the text editor to add a commit messagegit commit --amend
–> overwrite your last commit messagegit commit --amend --signoff
–> view and amend your sign-off branchgit commit --amend --signoff <hash>
–> view and amend your signoff for a specific commit on your sign-off branchgit commit -a
–> combine the git add and git commit steps into a single step (does not include newly created files)git config --global -l
–> list all global configuration valuesgit config --global keyname "value"
–> create a global valuegit fetch --all
–> refresh your local cache from the remote branches (does not download new branches)git help
–> access the built-in Git help documentation.git log --oneline
–> list previous commits with their unique idsgit pull
–> imports all updates from your default remote repo to your default local repo (usually, this is equivalent to 'git pull origin master')git pull origin master
–> import all updates from remote origin repo to local master repogit pull --rebase origin master
–> rebases (rather than merges) new remote changes to your local repositorygit push working mybranchname
–> push changes to the remote working directorygit push working --delete mybranchname
–> delete a remote branchgit remote -v
–> display remote directoriesgit reset HEAD myfile.txt
–> unstage a file that has already been stagedgit reset --hard
–> reset a current branch to its original stategit reset --hard HEAD^
–> remove last commitgit rm badfile.txt
–> delete a file (if the file is being tracked, be sure to add a commit message indicating the file has been deleted)git show --stat
–> see what your commit will look like before you push itgit status
–> display status of current branchgit version
–> displays the installed version of Git
Squash Commits
If you are in your local working branch and you've pushed up two commits to the remote git repository, you can combine them:
- Verify that you are in your local branch.
- Type: git rebase -i origin/master
- Your text editor will open and should show both of the commits, for example:
- pick 014e59c579 LP#1839359 Select element on login not accessible
- pick 9de92lsi9a LP#1839359 Select element on login not accessible
- Change the word "pick" in the second line to "fixup" then save and close the file
- Push the commit again, and force it to overwrite the previous commits:
- git push –force working lp1839359_login_select:user/jdoe/lp1839359_login_select
Common Bash Commands
cd
–> move back to the home foldercd foldername
–> move from the current folder to a child foldercd ..
–> move up in the folder hierarchy one levelclear
–> clears your command window giving you a fresh screen to work with (also, Ctrl-l)cp myfile.txt myfile.bak
–> copies file with new namediff myfile.txt otherfile.txt
–> shows differences between filesecho $ (tab tab)
–> returns list of all variablesecho $s (tab)
–> returns list of all variables that begin with 's'echo (variable name)
–> returns value of variablels
–> list visible folders and files in the current folderls -a
–> lists all of the files and folders in the current folder, including hidden filesls -l
–> lists all of the folders and files in the current folder with additional detail such as last modified timestampman (name of command)
–> opens manual for that commandmkdir newfoldername
–> create a new foldermv myfile.txt myfolder
–> moves file to foldernotepad++ newdocname.txt
–> create a new file and open it in notepad++notepad++ docname.txt
–> edit an existing file in notepad++pwd
–> see what folder you are currently inrmdir (myfoldername)
–> deletes folder
Vim Text Editor
The vim text editor is built into the bash console (similar to notepad in Windows).
vim
–> opens vim text editor in command modevim (filename)
–> opens file in vim text editor
Vim opens in command mode, which allows a variety of functions, but does not allow direct editing.
i
–> puts you into edit modeesc
–> puts you back into command mode from edit mode:q
–> takes you out of vim:w
–> saves your work:wq
–> saves & closes
newdevs/git/commands.1602104894.txt.gz · Last modified: 2022/02/10 13:34 (external edit)