-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_commands
More file actions
135 lines (93 loc) · 4.5 KB
/
git_commands
File metadata and controls
135 lines (93 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#git book and documentation:
http://git-scm.com/book/en/v2
#git reference
http://gitref.org
#git cheat-sheat
https://www.linux.com/learn/tutorials/864504-your-real-world-git-cheat-sheet-
Directory:
A folder used for storing multiple files.
Repository:
A directory where Git has been initialized to start version controlling your files.
git init #makes the current directory into a git repository (it puts it to index in ./.git ??)
git status
git status -s #for short info
staged:
Files are ready to be committed.
unstaged:
Files with changes that have not been prepared to be committed.
untracked:
Files aren't tracked by Git yet. This usually indicates a newly created file.
deleted:
File has been deleted and is waiting to be removed from Git.
git add foo.txt #adds the new file into stage/index??)
git add '*.txt' #adds all txt files recursively - also from subdirectories (single or double quots???)
#without quotes: shell does the search in current dir, with quotes: git does the search recursively
add all:
You can also type git add -A . where the dot stands for the current directory, so everything in and beneath it is added.
The -A ensures even file deletions are included.
git reset:
You can use git reset <filename> to remove a file or files from the staging area.
git commit -m "blah bla" #to put changes from index to actual repository there is a need to commit (-m "message description")
#A "commit" is a snapshot of our repository.
git log #views previous actions with id number, author, date, manual message
git log --summary #more info
#to push your local repo to an existing github repo you need to give your local repo a remote name and and give it the URL address
#typical to name main remote repo 'origin'
git remote add origin https://github.com/try-git/try_git.git #this gives your local repo a remote name (origin) and pairs ts with URL
#push local changes (commits) to the origin remote repo
#name of remote: origin
#default local branch name: master
#-u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do
git push -u origin master
git push
#if remote repo has changed we can pull the changes to the local repo
git pull origin master
#Use the command 'git stash' to stash your changes(do not commit them yet when pulling), and 'git stash apply' to re-apply your changes after your pull.
#HEAD points to your most recent commit
#to compare your pull with your most recent commit (compare both staged and unstaged with committed)
git diff HEAD
#to view differences between the staged files and the ???last commit???
git diff --staged
#differences between unstaged and latest commit
git diff
#differences between unstaged and staged version (ready for commit)
git diff -cached
#to remove file from stage/index
git reset foo.txt
git reset octofamily/octodog.txt
#Files can be changed back to how they were at the last commit by using the command:
#Go ahead and get rid of all the changes since the last commit for octocat.txt
#--space tells git there are no more options after --
#This way if you happen to have a branch named octocat.txt, it will still revert the file, instead of switching to the branch of the same name.
git checkout -- <target>.
git checkout -- octocat.txt
#create branch 'clean_up' from the main 'master'
git branch clean_up
#view branches
git branch
#switch branches
git checkout <branch>
git checkout clean_up_branchname
#to checkout and create a branch at the same time
git checkout -b new_branch
#this is the same as
git branch new_branch
git checkout new_branch
#remove file from disk and stage the removal for git
git rm foo.txt
git rm '*.txt' #for all txt files recursively
git rm -r foo_folder #for folder and all it contains
#commit branch change
git status #to see what you are going to do
git commit -m 'description'
#if you rm file but not git rm, it still has to be git rm, or use option -a with git commit, it will autoremove it from git
git commit -am "Delete stuff"
#pull request:
#you can request someone to pull your changes and review it before you merge your changed branch back to the master branch
#to merge a branch into master, change to master and merge the branch to it, you can delete the branch if you will not need it anymore
git checkout master
git merge clean_up_branchname
git branch -d clean_up_branchname
#you can only delete branch with -d option if it has been merged. if not, use -f -d (force delet), same as -D (short for -f -d)
#update local repo to the latest commit (fetch and merge remote changes)
git pull