-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-commands
136 lines (101 loc) · 4.56 KB
/
git-commands
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
134
135
REBASE YO BRANCH w/ MASTER
==========================
- git pull --rebase origin <branch e.g., master | develop | etc>
- git push -f
NOTE: **do not** do a git pull between the rebase and the push -f, as you might be instructed from poorly written git messages if there
are conflicts to resolve. Simply resolve those conflicts, then git add / commit them. Doing a git pull on a rebase will screw
up your commit history (will double the number of commits based on the pull, etc...?).
INFO commands
===================
# SORTED BY LATEST COMMITS
git branch -a --sort=-committerdate
# SORTED BY LATEST AND show all remote branches, with dates of last commit:
git for-each-ref --sort=committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'
alias branches="git for-each-ref --sort=committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'"
IGNORE FILES:
============
- git update-index --assume-unchanged
GITLAB CREATE REMOTE BRANCH
===================
- git checkout -b geoconfigs origin/develop
- git push origin HEAD:geoconfigs
PR commands
===================
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
# switch to PR #999
- emacs .git/config and add this line: fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
- Fetch PRs locally: $ git fetch origin
- Checkout a particular PR: $ git checkout pr/999
_______________
O L D J U N K
(might not be good)
_______________
Check Out Commands
===================
git pull origin pull/<PULL REQUEST ID>/head
REBASE fork
==============
git remote add upstream https://github.com/opentripplanner/otp-ui.git
git pull
git fetch upstream
git branch -a
git rebase upstream/master
git status
git push
MERGE branch
==================
git checkout master
git pull
git checkout vehicles
git pull
git merge master
git commit -a -m "merged latest master onto my feature branch"
git push
# NOTE: you should now be able to create a PR and it should be realtively clean (just files you changed in your feature branch)
REBASE branch w/master -- NOTE, this can be funky (see MERGE above as an alternate)
==================
git checkout master
git pull
git checkout vehicles
git pull
Working with FORKZ:
===================
I (John Z) use a rebase workflow in a similar scenario for repos I've forked from. I take a little longer way to do the same thing Grant is suggesting, but it keeps everything reliably separated for me at least. I generally only pull upstream into master and in my forked repo I leave master alone, treating it as my pivot branch between the two origins. I then rebase master into whatever I am working on locally.
Fork project
Clone fork locally
Fork is now origin
Create a new branch in your local fork to work in: git checkout -b working
Set original as "upstream" remote: git remote add upstream https://github.com/ORIGINAL_REPO
Checkout master and run: git checkout master && git pull upstream master
Checkout working and run: git checkout working && git rebase master
'''
# do this once to set up local repo
git clone [email protected]:TriMetPDX/otp-react-redux.git
git remote add upstream https://github.com/opentripplanner/otp-react-redux.git
git checkout -b tm_vehicles
git push --set-upstream origin tm_vehicles
# repeat whenever you want to rebase the fork's parent
git checkout master && git pull upstream master
git checkout trimet-dev && git pull upstream trimet-dev
git checkout tm_vehicles && git rebase trimet-dev
# NOTE: might not make any changes to trimet-mod-otp, so may not need do this, but...
# do this once
git clone [email protected]:TriMetPDX/trimet-mod-otp.git
git remote add upstream https://github.com/conveyal/trimet-mod-otp.git
git checkout -b tm_vehicles
git push --set-upstream origin tm_vehicles
# repeat whenever you want to rebase the fork's parent
git checkout master && git pull upstream master
git checkout tm_vehicles && git rebase master
'''
NOTE: your local commit hashes changed in the 'working' branch, but you've incorporated everything from the upstream master into your local project.
Pivot point from github to local gitlab:
=========================================
git clone https://github.com/conveyal/trimet-mod-otp.git
git remote rm origin
git remote add origin [email protected]:mod/trimet-mod-otp.git
git remote add upstream https://github.com/conveyal/trimet-mod-otp.git
git push origin master -u
git pull upstream master
git fetch upstream
git fetch upstream --prune